PDA

View Full Version : Solved: Cycle through all active docs in Word?



clhare
10-26-2005, 11:32 AM
Can anyone help me with a macro that will allow me to count all my open Word documents, run a second macro in each of them, then stop, leaving them all on screen? I tried the following, but it tends to stop before it's gone through all of the documents:



Dim doc As Document
For Each doc In Application.Documents
Call NextMacro
Next doc


Is this possible? Any help is greatly appreciated!

Norie
10-26-2005, 01:08 PM
Cheryl

You have the correct syntax for looping through the documents.

What does NextMacro do?

clhare
10-27-2005, 04:19 AM
I used "Next Macro" as a default. The macro to be run on each document (which are actually templates) will change some text, correct some formatting, add AutoText.

I need to somehow make sure that all the open documents get the updates and none are skipped. Is there a way to make sure of that other than having the macro save and close each one? Once the updates are made, I have to manually updates the macros in them all.

Thanks for your help!

mdmackillop
10-27-2005, 05:29 AM
Hi Cheryl,
Maybe a little clumsey, but might give some reassurance. You could also change it to look for False items instead.
Regards
MD


Sub DoThings()
Dim Doc As Document, Done As Boolean
For Each Doc In Application.Documents
If NextMacro(Doc) = True Then msg = msg & ActiveDocument.Name & vbCr
Next Doc
MsgBox msg
End Sub
Function NextMacro(Doc) As Boolean
Doc.Activate
DoEvents
Test = True
If Test = True Then 'Test for changes done
NextMacro = True
Else
NextMacro = False
End If

End Function