Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Jun 2002
    Location
    Johannesburg, Gauteng, South Africa
    Posts
    59
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Make opened document active(2000 SR-1)

    Hi, I have a problem that I hope someone can assist me with. The scenario is as follows:
    I have a macro that runs when a document is opened, asks for information vua a UserForm and pastes that information into the document at a bookmark. This all works fine when the only opened document is the document I am working on. The problem comes in when I already have one or more documents open and then open the document I wish to change. I cannot seem to get that document to become the active document to paste the information.
    For example, if I have Doc1 and Doc2 open and (with Doc2 active), I open (File..Open..) Doc3 (which is the Doc I want to alter), my macro runs but pastes the data into Doc2. (If Doc1 was active when Doc3 was opened, it pastes it into Doc1).

    Any help would be greatly appreciated.

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Make opened document active(2000 SR-1)

    The usual cause of this is failing to Unload your userform in between documents.
    When you finish processing a document, don't use Me.Hide or frmMyForm.Hide, use Unload frmMyForm.

    The other possibility is that the newly opened document really isn't active. How do you run your Macro, if it is from a DocumentOpen application level event then you should be called with a parameter that points to the correct document.

    StuartR

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Make opened document active(2000 SR-1)

    Usually, opening a document in code makes it the active document. But to make sure, you could use code like this:

    Dim oDoc As Document
    Set oDoc = Documents.Open("F:WordTest.doc")
    oDoc.Activate

    BTW, you don't actually need to make the document active. You can use ranges, making you independent of which document is active:

    Dim oDoc As Document
    Dim oRang As Range
    Set oDoc = Documents.Open("F:WordTest.doc")
    Set oRang = oDoc.Bookmarks("MyLocation").Range
    oRang.Paste

Posting Permissions

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