Article ID: 182180
Article Last Modified on 6/17/2005
Doc1.doc
Doc2.doc
Doc3.doc
Doc2.doc
Doc2.doc
Sub DocCollection()
Dim wDoc As Window
' Loop through all Windows currently open.
For Each wDoc In Windows
' Display name of document open in the current window.
MsgBox wDoc.Document.name
Next
End Sub
If you have several windows that contain the same document, and if these
windows are open at the same time, modify the code to check for duplicate
window names, as in the following example:
Sub DocCollection()
Dim wDoc As Window
Dim sCap As String
' Loop through all Windows currently open.
For Each wDoc In Windows
' Get the Window caption.
sCap = wDoc.Caption
' If the document open in the current window
' is a duplicate window (signified by the
' document name followed by a colon and
' the window number in the Caption property).
If InStr(1, sCap, ":") > 0 Then
' and if the number equals 1 (first copy of document).
If Mid$(sCap, InStr(1, sCap, ":") + 1, 1) = "1" Then
' Return the document name.
MsgBox wDoc.Document.Name
End If
' If the window caption does not contain a colon,
' return the window's document name.
Else
MsgBox wDoc.Document.Name
End If
Next
End Sub
181058 OFF98: How to Run Sample Code from Knowledge Base Articles
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: wordcon vb vba vbe
Keywords: kbbug kbmacroexample kbpending KB182180