Hello oh mighty geniuses of VBA!
I need some more help.
I'm trying to code a macro which will run through a document changing styles over to another code. I have about 80 documents which I need to reformat which are being sent to me by people with no idea of word formatting, so they're all over the place and no two are the same.
Therefore, the styles in each document are not identical. To combat that problem, I was trying to incorporate If statements into the code, however it doesn't seem to like it, so I'm obviously doing it wrong.
This is the code I have:
However, it's not doing what it should. When I run the macro, I get a run time error 5941 on the first line saying the requested member of the collection doesn't exist. Shouldn't it just be skipping that section of code if AppendixHeader doesn't exist? "1" points to the next lot of replacing formatting. Help!!Code:If Selection.Find.Style = ActiveDocument.Styles("Appendix Header") = True Then Selection.Find.Replacement.ClearFormatting Selection.Find.Replacement.Style = ActiveDocument.Styles("Heading 6") 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:=wdReplaceAll Else: GoTo 1 End If