Determining which Word documents are open (from Access 2003 VBA)

I want to insert data in a Word document that is already open. To do this, I need to be able to fill a combo with a list of currently open document titles for the user to select from.

How do I determine which documents are open, and what handle do I get back to access them?
LVL 9
crescendoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
This snippet will return the document object if it is open
Function GetOpenDoc(strDocFileName As String) As Word.Document
    Dim wdApp As Word.Application
    Dim wdDoc As Word.Document
    
    On Error GoTo ExitFunction
    Set wdApp = GetObject(, "Word.Application")
    On Error GoTo 0
    For Each wdDoc In wdApp.Documents
        If UCase$(wdDoc.FullName) = UCase$(strDocFileName) Then
            Set GetOpenDoc = wdDoc
            Exit Function
        End If
    Next wdDoc
ExitFunction:
End Function

Open in new window

0
GrahamSkanRetiredCommented:
This code will return an array of open document names
Function GetOpenDocs() As Variant
    Dim wdApp As Word.Application
    Dim wdDoc As Word.Document
    Dim OpenDocs() As String
    
    Dim w As Integer
    On Error GoTo ExitFunction
    Set wdApp = GetObject(, "Word.Application")
    On Error GoTo 0
    For Each wdDoc In wdApp.Documents
        ReDim Preserve OpenDocs(w)
        OpenDocs(w) = wdDoc.FullName
        w = w + 1
    Next wdDoc
    GetOpenDocs = OpenDocs()
ExitFunction:
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crescendoAuthor Commented:
Sorry for the delay in accepting, called away unexpectedly. Both answers really helpful, thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.