PDA

View Full Version : Solved: Searching for Column Break following a Heading 1



janaboo13
09-07-2012, 01:49 PM
I need a macro that searches for the first column break that follows a Heading 1, then move to the next paragraph (which happens to be in column 2 of a 2-column page layout). Then I want to change the before spacing value to "0."

I recorded a macro that searches every column break, but I only want to find the one following each Heading 1 in each new section.

Can anyone help me, please? Thank you so much.

Desperate in Seattle!

fumei
09-07-2012, 02:41 PM
Did you try recording a macro that finds each Heading 1?

You need to combine them.

Find each heading 1 THEN find the column break.

janaboo13
09-10-2012, 07:03 AM
I'll try that...thanks!

janaboo13
09-10-2012, 10:12 AM
Fumei,

OK...must be Monday morning fog brain! I've was successful in recording a macro to find Heading 1, then find the next column break, move the cursor to the next paragraph and then change the before spacing value to "0."

So it was successful for the first Heading 1. Here's where I always trip...how to move through the document to all Heading 1s?

Here is my code so far:
Option Explicit
Sub Macro2()
'
' 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
.MatchByte = False
.CorrectHangulEndings = True
.HanjaPhoneticHangul = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute

Selection.Find.ClearFormatting
With Selection.Find
.Text = "^n"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.CorrectHangulEndings = True
.HanjaPhoneticHangul = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute

Selection.MoveRight Unit:=wdCharacter, Count:=1
With Selection.ParagraphFormat

.SpaceBefore = 0

End With
End Sub


I tried some loop strategies and those either didn't work, looped indefinitely, or just got hung up.

Thank so so much for any help.

:dunno