C
Chuck
Hi,
I regularly receive large documents (hundreds of pages each) that need
re-formatting. I need a macro to automate the re-formatting, but the recorded
versions do not work. For example, I need to select paragraphs on the basis
of the first two characters in the paragraph, then replace every comma in the
paragraph (or semicolon in different set of paragraphs) with a ^p . However,
when the macro is run, every comma in the document is replaced, I presume
because the action of creating a new paragraph removes the selection.
Any suggestions on this will be appreciated. My current code is below:
Sub CitationFix()
'
' CitationFix Macro
'
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^pDE "
.Replacement.Text = "^p "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ", "
.Replacement.Text = "^p "
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
I regularly receive large documents (hundreds of pages each) that need
re-formatting. I need a macro to automate the re-formatting, but the recorded
versions do not work. For example, I need to select paragraphs on the basis
of the first two characters in the paragraph, then replace every comma in the
paragraph (or semicolon in different set of paragraphs) with a ^p . However,
when the macro is run, every comma in the document is replaced, I presume
because the action of creating a new paragraph removes the selection.
Any suggestions on this will be appreciated. My current code is below:
Sub CitationFix()
'
' CitationFix Macro
'
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^pDE "
.Replacement.Text = "^p "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ", "
.Replacement.Text = "^p "
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub