![]() |
#1
|
||||
|
||||
![]()
I have created a macro to take out repeated paragraph marks and replace the with just one. However the code is quite lone and I was sure that there was a way to clean it up. Could anyone give me some advice, here is my code.
Sub Remove_paragraph() ' ' Remove_paragraph Macro ' Macro to remove more the one paragraph mark, dow to just one.Also fixes the paragraph spacing for nomer and body font. ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "^p^p^p^p^p^p^p^p^p^p" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "^p^p^p^p^p^p^p^p^p" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "^p^p^p^p^p^p^p^p" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "^p^p^p^p^p^p^p" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "^p^p^p^p^p^p" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "^p^p^p^p^p" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "^p^p^p^p" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "^p^p^p" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll 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 Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.ClearFormatting With Selection.Find.Font .Size = 5.5 .Bold = False .Italic = False End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "^p" .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 'chang Normel style padding With ActiveDocument.Styles("Normal").ParagraphFormat .LeftIndent = InchesToPoints(0) .RightIndent = InchesToPoints(0) .SpaceBefore = 6 .SpaceBeforeAuto = False .SpaceAfter = 6 .SpaceAfterAuto = False .LineSpacingRule = wdLineSpaceSingle .Alignment = wdAlignParagraphLeft .WidowControl = False .KeepWithNext = False .KeepTogether = False .PageBreakBefore = False .NoLineNumber = False .Hyphenation = True .FirstLineIndent = InchesToPoints(0) .OutlineLevel = wdOutlineLevelBodyText .CharacterUnitLeftIndent = 0 .CharacterUnitRightIndent = 0 .CharacterUnitFirstLineIndent = 0 .LineUnitBefore = 0 .LineUnitAfter = 0 .MirrorIndents = False .TextboxTightWrap = wdTightNone End With ActiveDocument.Styles("Normal").NoSpaceBetweenPara graphsOfSameStyle = _ False With ActiveDocument.Styles("Normal") .AutomaticallyUpdate = False .BaseStyle = "" .NextParagraphStyle = "Normal" End With 'chang body text styles padding With ActiveDocument.Styles("Body Text").ParagraphFormat .LeftIndent = InchesToPoints(0.07) .RightIndent = InchesToPoints(0) .SpaceBefore = 6 .SpaceBeforeAuto = False .SpaceAfter = 6 .SpaceAfterAuto = False .LineSpacingRule = wdLineSpaceSingle .Alignment = wdAlignParagraphLeft .WidowControl = False .KeepWithNext = False .KeepTogether = False .PageBreakBefore = False .NoLineNumber = False .Hyphenation = True .FirstLineIndent = InchesToPoints(0) .OutlineLevel = wdOutlineLevelBodyText .CharacterUnitLeftIndent = 0 .CharacterUnitRightIndent = 0 .CharacterUnitFirstLineIndent = 0 .LineUnitBefore = 0 .LineUnitAfter = 0 .MirrorIndents = False .TextboxTightWrap = wdTightNone End With ActiveDocument.Styles("Body Text").NoSpaceBetweenParagraphsOfSameStyle = _ False With ActiveDocument.Styles("Body Text") .AutomaticallyUpdate = False .BaseStyle = "Normal" .NextParagraphStyle = "Body Text" End With End Sub |
#2
|
|||
|
|||
![]()
Peter,
Try: Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oRng As Word.Range Set oRng = ActiveDocument.Range With oRng.Find .ClearFormatting .Text = "^13{2,}" .Replacement.Text = "^p" .MatchWildcards = True .Execute Replace:=wdReplaceAll End With End Sub |
#3
|
||||
|
||||
![]()
Greg thanks.
Could you explain it to me, just so I will know. I get the .Replacement.Text = "^p" But what is Dim oRng As Word.Range Set oRng = ActiveDocument.Range With oRng.Find .ClearFormatting .Text = "^13{2,}" |
#4
|
|||
|
|||
![]()
Dim is a declaration statement. oRng is a variable. Word.Range is an object.
I used DIM to declare the variable oRng as was Word.Range object. I then set the oRng variable object = to the ActiveDocument.Range The I searched the range for the text "^13" (I used ^13 because "^p" is invalid in the find what when wildcards are used.) "{2,}" is a wildcard statement meaning to search for 2 or more instances. See "Learn to love ranges" here: http://gregmaxey.com/word_tip_pages/vba_basics.html |
#5
|
||||
|
||||
![]()
Got it thanks.
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Any easy way to clean up bulleted list? | New Daddy | Word | 2 | 08-29-2013 06:00 AM |
custom icon, undo/redo for macro, permanent macro | Rapier | Excel | 0 | 08-05-2013 06:30 AM |
![]() |
TTN | Office | 22 | 07-14-2012 01:48 AM |
![]() |
robinarm | Outlook | 2 | 11-03-2011 02:46 AM |
How do I assign a macro to a button when the macro is in my personal workbook? | foolios | Excel Programming | 2 | 07-27-2011 02:41 PM |