S
Steve Wylie
We sometimes get documents where paragraph numbering needs changing
and for one reason or another we cannot use automatic paragraph
numbering in the document, just manual numbering. I am trying to
write a macro that will enable you to renumber basic paragraphs in a
document (nothing fancy, just ones numbered 1, 2, 3, 4 etc).
I am using the Selection.Find method to search for the first number,
then I want to replace it with another (incremented) number, search
for the next number, replace that, and so on till the end of the
document. I cannot get this to work. If finds the first number and
replaces it but then stops. Here's the code I've got so far, and I
daresay I'm going about it the wrong way.
Sub ReplaceNos()
Dim a As Integer
Number = 1
Selection.Find.ClearFormatting
With Selection.Find
.Text = Number
.Forward = True
.Wrap = wdStop
.Format = False
Do While .Execute
if Selection.Information(wdHorizontalPositionRelativeToTextBoundary)/72<2
then
Number = Number + 1
a = Selection.Text
a = a + 5
Selection.Text = a
Selection.Collapse Direction:=wdCollapseEnd
End if
Loop
End With
End Sub
This *should* search for the digit 1 and, if it is within the first 2
inches of the left margin, replace it with 6. Then search for "2",
replace it with 7, etc etc.
Silly question... why does it not work? I really need a lot more
knowledge of how the selection.find method works, I think!
Steve Wylie
and for one reason or another we cannot use automatic paragraph
numbering in the document, just manual numbering. I am trying to
write a macro that will enable you to renumber basic paragraphs in a
document (nothing fancy, just ones numbered 1, 2, 3, 4 etc).
I am using the Selection.Find method to search for the first number,
then I want to replace it with another (incremented) number, search
for the next number, replace that, and so on till the end of the
document. I cannot get this to work. If finds the first number and
replaces it but then stops. Here's the code I've got so far, and I
daresay I'm going about it the wrong way.
Sub ReplaceNos()
Dim a As Integer
Number = 1
Selection.Find.ClearFormatting
With Selection.Find
.Text = Number
.Forward = True
.Wrap = wdStop
.Format = False
Do While .Execute
if Selection.Information(wdHorizontalPositionRelativeToTextBoundary)/72<2
then
Number = Number + 1
a = Selection.Text
a = a + 5
Selection.Text = a
Selection.Collapse Direction:=wdCollapseEnd
End if
Loop
End With
End Sub
This *should* search for the digit 1 and, if it is within the first 2
inches of the left margin, replace it with 6. Then search for "2",
replace it with 7, etc etc.
Silly question... why does it not work? I really need a lot more
knowledge of how the selection.find method works, I think!
Steve Wylie