Hi everyone,
First post for me in the forum, although I've been through here many times. Thanks for everything so far.
Here my problem. I'm writing a macro to format Word documents. Nothing too complicated (font and paragraph formatting, search and replace, etc.). The main macro 'Formatting' calls up five separate macros one after the other.
One is made to search for hidden text (DecFormat05_HiddenText). If found, it makes it visible, applies font colour red and then moves on the the next (Do While Loop). It also counts the number of occurrences and posts a message warning the user that these changes were made.
This macro works fine when I run it on its own, but when I run it through the main macro it finds the first instance and then exits the loop (with the message). No idea what it could be. I would be grateful for any pointers.
Just for info, most of my macros are intially recorded then improved through online research if at all possible. I really should get some formal training to take it to the next level ...
Thanks in advance!
Kobber
Here is the code:
1. the main macro which calls the others
Sub Formatting()
Call TCs_TurnOFF ' Turns off Track Changes
Call DecFormat01_SearchReplace ' Does some search and replace operations
Call DecFormat02_HardSpacesDashes ' Inserts hard spaces and dashes as necessary
Call DecFormat03_Page ' Page formatting
Call DecFormat04_FontAndParagraph ' Font and paragraph formatting
Call DecFormat05_HiddenText ' Reveals hidden text
Selection.HomeKey Unit:=wdStory
MsgBox ("Formatting complete.")
End Sub
2. DecFormat05_HiddenText
Sub DecFormat05_HiddenText()
Dim i As Integer
i = 0
ActiveWindow.ActivePane.View.ShowAll = True
Selection.Find.ClearFormatting
Selection.Find.Font.Hidden = True
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Hidden = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceOne 'All
Selection.Font.Color = wdColorRed
If Selection.Find.Found = True Then
Do While Selection.Find.Found
Selection.Find.Execute Replace:=wdReplaceOne 'All
Selection.Font.Color = wdColorRed
Selection.Collapse Direction:=wdCollapseEnd
i = i + 1
Loop
MsgBox ("Hidden text was detected " & i & " time(s) in this document. " & _
"It has been made visible and formatted to appear red. " & vbCr & vbCr & _
"Please check this text as soon as this macro has finished running.")
End If
End Sub