Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-22-2016, 10:05 AM
milk4140 milk4140 is offline Macro stops partway through endnotes Windows 7 64bit Macro stops partway through endnotes Office 2013
Novice
Macro stops partway through endnotes
 
Join Date: Jul 2016
Posts: 1
milk4140 is on a distinguished road
Default 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
Reply With Quote
Reply

Tags
endnotes, macro problem, macro vba word



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro stops partway through endnotes When applying styles word is automatically reverting to "strong" style partway through my document Victoria S Word 3 11-17-2015 12:51 PM
Macro stops partway through endnotes Header stops partway through document Eduardo Care Word 3 10-09-2015 03:55 PM
Macro stops partway through endnotes Error on macro to insert endnotes on Mac mbk Word VBA 11 12-20-2012 01:03 AM
Macro stops partway through endnotes How to convert endnotes in a text doc to Word endnotes? Dickison Word VBA 4 10-06-2012 09:11 PM
Macro stops partway through endnotes Excel stops responding after starting macro Catalin.B Excel Programming 2 09-07-2012 04:05 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:07 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft