janaboo13
02-16-2015, 12:15 PM
Greetings Experts!
I need a macro that allows me to search for a style (Heading 1) and when found, move the cursor to the end of the line and search for the first Heading 2 style that follows. When that style is found, I want to change the .SpaceBefore to 0.
I can get this to work with only one search, but I'm lost with two searches and the loop so that I can search the entire document.
I've recorded the actions:
Sub Macro1()'
' Macro2 Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchControl = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 2")
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchControl = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute
With Selection.ParagraphFormat
.SpaceBefore = 0
End With
End Sub
You can't know how I appreciate this forum and all the help that Greg Maxey and Graham Mayor (and others over the past couple of years) have given me, so any additional help would not go unappreciated.
Thanks! Jan
I need a macro that allows me to search for a style (Heading 1) and when found, move the cursor to the end of the line and search for the first Heading 2 style that follows. When that style is found, I want to change the .SpaceBefore to 0.
I can get this to work with only one search, but I'm lost with two searches and the loop so that I can search the entire document.
I've recorded the actions:
Sub Macro1()'
' Macro2 Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchControl = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 2")
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchControl = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute
With Selection.ParagraphFormat
.SpaceBefore = 0
End With
End Sub
You can't know how I appreciate this forum and all the help that Greg Maxey and Graham Mayor (and others over the past couple of years) have given me, so any additional help would not go unappreciated.
Thanks! Jan