P
Petra Liverani
I have recorded two macros and put
"Do Until Selection.Endkey" before and "Loop" after them.
One works and the other doesn't and I have no idea why.
'This one works - it involves finding some text, deleting
it, then copying adjacent text, finding upwards other text
and pasting the text previously found
Do Until Selection.EndKey
Selection.Find.ClearFormatting
With Selection.Find
.Text = "~~~"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Answer="
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Paste
Loop
'This one doesn't work - it involves finding a style,
moving to the next paragaph and selecting it and making
that paragraph a particular style
Do Until Selection.EndKey
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading
2")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1,
Extend:=wdExtend
Selection.Style = ActiveDocument.Styles("LD Body
Indent")
Loop
"Do Until Selection.Endkey" before and "Loop" after them.
One works and the other doesn't and I have no idea why.
'This one works - it involves finding some text, deleting
it, then copying adjacent text, finding upwards other text
and pasting the text previously found
Do Until Selection.EndKey
Selection.Find.ClearFormatting
With Selection.Find
.Text = "~~~"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Answer="
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Paste
Loop
'This one doesn't work - it involves finding a style,
moving to the next paragaph and selecting it and making
that paragraph a particular style
Do Until Selection.EndKey
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading
2")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1,
Extend:=wdExtend
Selection.Style = ActiveDocument.Styles("LD Body
Indent")
Loop