• activating new document (wd2000)

    Author
    Topic
    #382948

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #651547

      (Edited by carbonnb on 07-Feb-03 09:14. Thought of another question as soon as I clicked post.)

      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:fullpathtoyourtemplate.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?

      • #651567

        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

        • #651574

          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. sorry

        • #651889

          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

    • #651655

      Sounds like that TweakUI “don’t steal focus” issue in a new context. Do you run TweakUI?

      • #652190

        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!)…

        • #653139

          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?)

    Viewing 1 reply thread
    Reply To: activating new document (wd2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: