Article ID: 167876
Article Last Modified on 1/19/2007
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, which contain the same document, open at
the same time, modify the code to check for duplicate document window
names. For 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
173707 OFF97: 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 kbmacro kbpending kbprogramming KB167876