I'm writing a macro which goes through each shape, header and footer in a Word document individually and runs an external macro on it. This external macro was not written by me and I've no access to the code.
So I have the macro loop through all the objects in question and call the macro with Run, but the whole thing seems to stop running after the Run statement, and the macro appears to run on the whole document, excluding the headers and footers. Should I be using something else rather than Run?
VB Code:
Sub CleanWholeDocument() Dim sShape As Shape Dim fNote As Footnote Dim HeadFoot As HeaderFooter Dim sSection As Section For Each sSection In ActiveDocument.Sections For Each HeadFoot In sSection.Headers HeadFoot.Range.Select Application.Run MacroName:="tw4winClean.Main" Next HeadFoot Next sSection For Each fNote In ActiveDocument.Footnotes fNote.Range.Select Application.Run MacroName:="tw4winClean.Main" Next fNote For Each sShape In ActiveDocument.Shapes If sShape.TextFrame.HasText Then sShape.TextFrame.TextRange.Select Application.Run MacroName:="tw4winClean.Main" End If Next sShape Application.Run MacroName:="tw4winClean.Main" End Sub




Reply With Quote