#1
|
|||
|
|||
Macro stops partway through endnotes
I'm using macros in Word 2013 to modify journal article manuscripts in preparation for converting into HTML. One of the macros takes all of the italics in the manuscript and surrounds them with <em> tags. The macro I'm currently using looks at the body text and the endnotes as distinct sections and this half works. My problem is that the macro will convert the italics in some, but not always all of the endnotes. In some manuscripts it will works on all of the endnotes, in some manuscripts it only works in about the first half of the endnotes, in some manuscripts in only works on the first few endnotes.
I've made sure that all of the Endnotes have the 'Endnote Text' style applied before I run the macro, so I don't think the problem is there. I'm currently looking at the underlying Word XML to try and determine if there's some difference there that might account for the issue. If anyone has any ideas, I would greatly appreciate the help. Thanks! Current macro: Sub html_italics() ' ' ' Dim ThisRng As Range If Selection.Type = wdSelectionNormal Then GoTo SelectionOnly ' 'do body text Set ThisRng = ActiveDocument.StoryRanges(wdMainTextStory) With ThisRng.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = "" .Replacement.Text = "<em>^&</em>" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False ThisRng.Find.Execute Replace:=wdReplaceAll End With With ThisRng.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = " </em>" .Replacement.Text = "</em> " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False ThisRng.Find.Execute Replace:=wdReplaceAll End With With ThisRng.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = "^p</em>" .Replacement.Text = "</em>^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False ThisRng.Find.Execute Replace:=wdReplaceAll End With With ThisRng.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = ".</em>" .Replacement.Text = "</em>." .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False ThisRng.Find.Execute Replace:=wdReplaceAll End With With ThisRng.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = "<em></em>" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False ThisRng.Find.Execute Replace:=wdReplaceAll End With ' 'do endnotes if they're there If existence_of_Endnotes = True Then Set ThisRng = ActiveDocument.StoryRanges(wdEndnotesStory) With ThisRng.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = "" .Replacement.Text = "<em>^&</em>" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False ThisRng.Find.Execute Replace:=wdReplaceAll End With With ThisRng.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = " </em>" .Replacement.Text = "</em> " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False ThisRng.Find.Execute Replace:=wdReplaceAll End With With ThisRng.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = "^p</em>" .Replacement.Text = "</em>^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False ThisRng.Find.Execute Replace:=wdReplaceAll End With With ThisRng.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = ".</em>" .Replacement.Text = "</em>." .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False ThisRng.Find.Execute Replace:=wdReplaceAll End With With ThisRng.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = "<em></em>" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False ThisRng.Find.Execute Replace:=wdReplaceAll End With End If ' 'this part does only the selected text SelectionOnly: With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = "" .Replacement.Text = "<em>^&</em>" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False Selection.Find.Execute Replace:=wdReplaceAll End With With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = " </em>" .Replacement.Text = "</em> " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False Selection.Find.Execute Replace:=wdReplaceAll End With With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = "^p</em>" .Replacement.Text = "</em>^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False Selection.Find.Execute Replace:=wdReplaceAll End With With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = ".</em>" .Replacement.Text = "</em>." .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False Selection.Find.Execute Replace:=wdReplaceAll End With With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Font.Italic = True .Replacement.Font.Italic = False .Text = "<em></em>" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False Selection.Find.Execute Replace:=wdReplaceAll End With GoTo FinalCleanup FinalCleanup: With Selection.Find .ClearFormatting .Replacement.ClearFormatting End With End Sub |
Tags |
endnotes, macro problem, macro vba word |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
When applying styles word is automatically reverting to "strong" style partway through my document | Victoria S | Word | 3 | 11-17-2015 12:51 PM |
Header stops partway through document | Eduardo Care | Word | 3 | 10-09-2015 03:55 PM |
Error on macro to insert endnotes on Mac | mbk | Word VBA | 11 | 12-20-2012 01:03 AM |
How to convert endnotes in a text doc to Word endnotes? | Dickison | Word VBA | 4 | 10-06-2012 09:11 PM |
Excel stops responding after starting macro | Catalin.B | Excel Programming | 2 | 09-07-2012 04:05 AM |