S
Shimon
Hi,
I have a macro that inserts SEQ numbers under figures by replacing a string
" Figure:" with "Figure" + "SequenceNumber".
This code loops while the string is found. If it is not found then it exits
the SUB.
One problem is that it does not start the loop unless I do a find first.
The main problem righ now is that at the end it enters a second sequence
number before it exits.
I would like either to fix the loop so that it works properly, or to add an
undo right before the exist SUB statement.
Any help is greatl appreciated.
Should I post this code in the numbering newsgroup, or is this simple stuff
for VBA programmers.
Thanks,
Shimon
Sub hInsertNumLooped()
'Replaces the text " Figure: " with Figure: and a reference number
'in order to build a table of figures .
'
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " Figure: "
.Replacement.Text = "Figure: "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceOne
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:=
_
"SEQ Figure \*ARABIC", PreserveFormatting:=True
Selection.TypeText Text:=" "
For i = 1 To 10000
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " Figure: "
.Replacement.Text = "Figure: "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
If Not .Found Then
MsgBox ("Fix the last figure number")
Exit Sub
End If
End With
Selection.Find.Execute Replace:=wdReplaceOne
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:=
_
"SEQ Figure \*ARABIC", PreserveFormatting:=True
Selection.TypeText Text:=" "
Next i
MsgBox ("Fix the last number and add a Table of figures")
End Sub
I have a macro that inserts SEQ numbers under figures by replacing a string
" Figure:" with "Figure" + "SequenceNumber".
This code loops while the string is found. If it is not found then it exits
the SUB.
One problem is that it does not start the loop unless I do a find first.
The main problem righ now is that at the end it enters a second sequence
number before it exits.
I would like either to fix the loop so that it works properly, or to add an
undo right before the exist SUB statement.
Any help is greatl appreciated.
Should I post this code in the numbering newsgroup, or is this simple stuff
for VBA programmers.
Thanks,
Shimon
Sub hInsertNumLooped()
'Replaces the text " Figure: " with Figure: and a reference number
'in order to build a table of figures .
'
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " Figure: "
.Replacement.Text = "Figure: "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceOne
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:=
_
"SEQ Figure \*ARABIC", PreserveFormatting:=True
Selection.TypeText Text:=" "
For i = 1 To 10000
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " Figure: "
.Replacement.Text = "Figure: "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
If Not .Found Then
MsgBox ("Fix the last figure number")
Exit Sub
End If
End With
Selection.Find.Execute Replace:=wdReplaceOne
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:=
_
"SEQ Figure \*ARABIC", PreserveFormatting:=True
Selection.TypeText Text:=" "
Next i
MsgBox ("Fix the last number and add a Table of figures")
End Sub