Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-28-2013, 09:51 AM
Peter Carter's Avatar
Peter Carter Peter Carter is offline Need help on how to clean up my macro Windows 8 Need help on how to clean up my macro Office 2013
Novice
Need help on how to clean up my macro
 
Join Date: Mar 2013
Posts: 11
Peter Carter is on a distinguished road
Default Need help on how to clean up my macro

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
Reply With Quote
  #2  
Old 08-28-2013, 10:10 AM
gmaxey gmaxey is offline Need help on how to clean up my macro Windows 7 32bit Need help on how to clean up my macro Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
Also see: http://gregmaxey.com/word_tip_pages/cleanup_text.html
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 08-28-2013, 11:16 AM
Peter Carter's Avatar
Peter Carter Peter Carter is offline Need help on how to clean up my macro Windows 8 Need help on how to clean up my macro Office 2013
Novice
Need help on how to clean up my macro
 
Join Date: Mar 2013
Posts: 11
Peter Carter is on a distinguished road
Default

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,}"
Reply With Quote
  #4  
Old 08-28-2013, 11:23 AM
gmaxey gmaxey is offline Need help on how to clean up my macro Windows 7 32bit Need help on how to clean up my macro Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 08-28-2013, 11:32 AM
Peter Carter's Avatar
Peter Carter Peter Carter is offline Need help on how to clean up my macro Windows 8 Need help on how to clean up my macro Office 2013
Novice
Need help on how to clean up my macro
 
Join Date: Mar 2013
Posts: 11
Peter Carter is on a distinguished road
Default

Got it thanks.
Reply With Quote
Reply



Similar Threads
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
Need help on how to clean up my macro Clean an Email backup file TTN Office 22 07-14-2012 01:48 AM
Need help on how to clean up my macro Clean out "Other Calendars" 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

Other Forums: Access Forums

All times are GMT -7. The time now is 07:42 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