?
Solved

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

Posted on 2008-01-25
3
Medium Priority
?
364 Views
Last Modified: 2013-11-27
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?
0
Comment
Question by:crescendo
  • 2
3 Comments
 
LVL 77

Expert Comment

by:GrahamSkan
ID: 20744478
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
 
LVL 77

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 20744554
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
 
LVL 9

Author Closing Comment

by:crescendo
ID: 31425008
Sorry for the delay in accepting, called away unexpectedly. Both answers really helpful, thanks.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
A quick solution showing how to control and open a POS Cash Register Drawer using VBA with MS Access.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month5 days, 20 hours left to enroll

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question