Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Chicago, Illinois, USA
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check to see if a document is open (VBA in Office 97)

    I've written something that goes through a directory and attempts to do something to each document in the directory. It works fine, unless the document it attempts to access is already open (by another user). I am trying to find a test to determine if a document is already open--any assistance would be appreciated. Thanks in advance...

    Jennifer

  2. #2
    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: Check to see if a document is open (VBA in Office 97)

    If you are opening the document...

    If ActiveDocument.ReadOnly = False Then
    'make changes
    Else
    'log it for later?
    End If

    If you don't open it first, hmmm...

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check to see if a document is open (VBA in Office 97)

    Maybe <A target="_blank" HREF=http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q184982>this KB article</A> can help you.
    Francois

  4. #4
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Chicago, Illinois, USA
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check to see if a document is open (VBA in Office 97)

    That was my first thought, but it appears that having a document open doesn't make it appear to be "read only" from another machine (at least, it doesn't turn on the "read only" property).

    And--can a document be considered the "activedocument" when it isn't open?

    It's all very weird. I've found lots of code detailing how to process large directories of files programmatically with VBA, and nothing indicates how to handle files that are being currently modified by another user. It's very weird--I can't believe this hasn't come up.

    [edited to correct horrific spelling and grammar...sorry]

  5. #5
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Chicago, Illinois, USA
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check to see if a document is open (VBA in Office 97)

    Francois! Merci beaucoup!

    YES!! That did it! Thank you so much. I had searched the KB multiple times, and found Q159345 (which didn't work because it was checking to see if the document was open in the documents collection on the current machine). Somehow, I missed the article you linked. That is very useful...thanks very much.

    But it's led me to yet another problem (grrr). Now my code stops if it hits a mail merge document and can't find the data source. I have an on error resume next, but it doesn't see this as an error. So, I either need a function to determine if I'm looking at a Mail Merge document, or something that simply cancels the "can't find the data source" dialog box.

    Did I mention grr?? This is my first "real" vba project, and it's driving me nuts.

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check to see if a document is open (VBA in Office 97)

    I am absolutly not a Word specialist (I am an Access-freak or victim) but I found this in the help file of Word VBA:

    Using the MailMerge Object

    Use the MailMerge property to return the MailMerge object. The MailMerge object is always available regardless of whether the mail merge operation has begun. Use the State property to determine the status of the mail merge operation. The following example executes a mail merge if the active document is a main document with an attached data source.

    If ActiveDocument.MailMerge.State = wdMainAndDataSource Then
    ActiveDocument.MailMerge.Execute
    End If

    Hope this help
    Francois

Posting Permissions

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