Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    activating new document (wd2000)

    I've got some code that creates a new document based on a certain template, adds stuff to the document according to various saved text files, then (supposedly) displays the resulting document to the user. I assumed that .activate would make my document the active document and bring it to the front, but it doesn't seem to. It "activates" the taskbar button for that document, but I have to click it a couple of times to bring my document to the front. What do I add to my code to ensure my document comes to the fore when all the work is done?

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: activating new document (wd2000)

    <P ID="edit" class=small>(Edited by carbonnb on 07-Feb-03 09:14. Thought of another question as soon as I clicked post.)</P>Dave,

    Is the code running from Word or are you automating Word from another application?

    Are you using a line similar to this to create the new document?

    Set doc = Application.Documents.Add(Template:="c:fullpathtoy ourtemplate.dot", Visible:=False)

    Could you please post the code that you are using to create the document and the code you are using to try and activate the document?

    Did you turn off the screenupdating while running the code?
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    New Lounger
    Join Date
    Mar 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: activating new document (wd2000)

    The code's running from a Word global template.
    To create the document:
    Dim DocReport as Document
    (...code...)
    Set DocReport = Documents.Add(Template:=ThisDocument.FullName) 'note I didn't set visibility either way

    Later, to activate the document:
    DocReport.activate

    No, I didn't turn off screenupdating.
    HTH

  4. #4
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: activating new document (wd2000)

    Well Dave,

    I just tried a quick test and it worked fine for me. I don't know what to tell you now.

    Try explicitly setting the Visible parameter to true in the Documents.Add code.

    I actually had the document come to the front without using .activate.

    If there are any user forms open, try closing (or hiding them if you still need to use them) before the docReport.activate line.

    Other that that, I'm stumped. <img src=/S/sorry.gif border=0 alt=sorry width=15 height=15>
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: activating new document (wd2000)

    Sounds like that TweakUI "don't steal focus" issue in a new context. Do you run TweakUI?

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: activating new document (wd2000)

    Don't know if this will help, but in any case here's something different to try:

    Sub ActivateLatestWindow
    Dim n As Long
    n = Windows.Count
    Windows(n).Activate
    End Sub

  7. #7
    New Lounger
    Join Date
    Mar 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: activating new document (wd2000)

    I've just tried the code on a different machine: at work we're on Win2000 (definitely no TweakUI!), and it does what it's supposed to, the way it's expected to (which is the main thing, really, since it'll be used at work when it's all sorted out). On my machine at home (which was exhibiting the problem) I have WinXP, and possibly (I can't recall offhand) TweakUI. I'll have a look into it.
    In the meantime, I'll also have a go with Gary's code, see if that makes a difference.
    Thanks guys, I'll report back with the outcome (one way or the other!)...

  8. #8
    New Lounger
    Join Date
    Mar 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: activating new document (wd2000)

    Strangely, I now can't get it to replicate the problem - works fine now! (Though it WAS doing it all the time... must've been some specific set of circumstances, but I'm blown if I can work out what). Hmm... Anyway, no I wasn't running TweakUI on my home machine either, but I've kept hold of that code snippet in case it leaps up again. Sorry to have troubled you guys with a problem that seems to have gone away of its own accord!
    (If only they were all like that, huh?)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •