S
Sandi V
Good afternoon - I am trying to create a macro that cleans up a messy
document. What I've got so far is from recording a couple of short macros &
looking at the resulting code.
I recorded a macro to find all instances of two empty paragraphs & replace
with one, which gives me:
With Selection.Find.Text = "^p^p"
.Replacement.Text = "^p
I want this to loop until Word no longer finds two empty paragraph marks.
Can somebody help me with this? (My VBA skills are not great). Thanks in
advance!
Sandi
(code follows)
Sub FixDoc()
'
'Copy everthing but the last paragraph mark
Selection.EndKey Unit:=wdStory
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Copy
'New blank doc, paste unformatted
Documents.Add Template:="z:\templates\NewBlank.dot", NewTemplate:=False, _
DocumentType:=0
Selection.PasteAndFormat (wdPasteDefault)
'Remove direct formatting
Selection.WholeStory
Selection.Font.Reset
Selection.ParagraphFormat.Reset
WordBasic.ToolsBulletsNumbers Replace:=0, Type:=1, Remove:=1
With Selection.Find.Text = "^p^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Apply a Style
Selection.Style = ActiveDocument.Styles("TR Body Text 1,B1")
End Sub
document. What I've got so far is from recording a couple of short macros &
looking at the resulting code.
I recorded a macro to find all instances of two empty paragraphs & replace
with one, which gives me:
With Selection.Find.Text = "^p^p"
.Replacement.Text = "^p
I want this to loop until Word no longer finds two empty paragraph marks.
Can somebody help me with this? (My VBA skills are not great). Thanks in
advance!
Sandi
(code follows)
Sub FixDoc()
'
'Copy everthing but the last paragraph mark
Selection.EndKey Unit:=wdStory
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Copy
'New blank doc, paste unformatted
Documents.Add Template:="z:\templates\NewBlank.dot", NewTemplate:=False, _
DocumentType:=0
Selection.PasteAndFormat (wdPasteDefault)
'Remove direct formatting
Selection.WholeStory
Selection.Font.Reset
Selection.ParagraphFormat.Reset
WordBasic.ToolsBulletsNumbers Replace:=0, Type:=1, Remove:=1
With Selection.Find.Text = "^p^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Apply a Style
Selection.Style = ActiveDocument.Styles("TR Body Text 1,B1")
End Sub