PDA

View Full Version : Loop thru all opened word documents



elbartje
06-12-2017, 01:38 PM
Hi all

I want to loop thru all opened word documents but my code stays on the first selected file. It also only just loops 2 times even if I have more files opened.

the code :

Dim wd As Range

For Each wd In ActiveDocument.Words

wd.Select
MsgBox (wd.Document.Name)
'Do stuff

next wd

gmaxey
06-12-2017, 07:14 PM
The code you posted has nothing to do with looping through all opened documents.


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oDoc As Document
For Each oDoc In Documents
MsgBox oDoc.Name
Next
lbl_Exit:
Exit Sub
End Sub