J
jerem
Hi Greg, Ed, Russ, etc.
Greg, tried the code you gave me:
Sub ScrathMacroII()
Dim myArray As Variant
Dim i As Long
Dim oRng As Word.Range
myArray = Split("[A]|", "|") '[C] etc.
For i = 0 To UBound(myArray)
Set oRng = ActiveDocument.Range
With oRng.Find
..Text = myArray(i)
..Replacement.Text = ""
..Forward = True
..Wrap = wdFindStop
While .Execute
oRng.InsertAutoText
oRng.Collapse wdCollapseEnd
Wend
End With
Next i
End Sub
and it doesn't seem to do anything.
Ed, similar problem with the code below:
Sub Test()
ReplaceStuff ("[A]")
ReplaceStuff ("")
....
....
End Sub
Sub ReplaceStuff(pText As String)
Dim MyRange As Range
Dim FindString As String
FindString = Replace(Replace(pText, "[", "\["), "]", "\]")
With Selection.Find
Do While .Execute(FindText:=FindString, _
MatchWildcards:=True, _
Wrap:=wdFindContinue, _
Forward:=True) = True
Set MyRange = Selection.Range
MyRange.InsertAutoText
Loop
End With
End Sub
So.......just one more question with the code below -- rather than using the
Dim i As Integer
i = 4
Do
i = i - 1
and the Loop Until i = 0 to get my set of instructions to loop until all
[A]'s appearing in the document are replaced with similarly named autotext
entries (and the only reason I'm using these statements is because it's the
only way I know how to get the darn thing to loop)
I know all of you have been trying to help me by giving me other suggestions
(but it's not accomplishing what I need to get done) but the code I've come
up with does accomplish it. I just need something like
Keep repeating the instructions below
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[AB]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"AUTOTEXT [AB] ", PreserveFormatting:=False
Until there are no more to replace then go to the next set of instructions
following this one
I know there are Whiles and Wends but have tried to fool around with these
but can't seem to get them to work. I just need someone to get these
instructions to loop without use a counter. ?????????
Greg, tried the code you gave me:
Sub ScrathMacroII()
Dim myArray As Variant
Dim i As Long
Dim oRng As Word.Range
myArray = Split("[A]|", "|") '[C] etc.
For i = 0 To UBound(myArray)
Set oRng = ActiveDocument.Range
With oRng.Find
..Text = myArray(i)
..Replacement.Text = ""
..Forward = True
..Wrap = wdFindStop
While .Execute
oRng.InsertAutoText
oRng.Collapse wdCollapseEnd
Wend
End With
Next i
End Sub
and it doesn't seem to do anything.
Ed, similar problem with the code below:
Sub Test()
ReplaceStuff ("[A]")
ReplaceStuff ("")
....
....
End Sub
Sub ReplaceStuff(pText As String)
Dim MyRange As Range
Dim FindString As String
FindString = Replace(Replace(pText, "[", "\["), "]", "\]")
With Selection.Find
Do While .Execute(FindText:=FindString, _
MatchWildcards:=True, _
Wrap:=wdFindContinue, _
Forward:=True) = True
Set MyRange = Selection.Range
MyRange.InsertAutoText
Loop
End With
End Sub
So.......just one more question with the code below -- rather than using the
Dim i As Integer
i = 4
Do
i = i - 1
and the Loop Until i = 0 to get my set of instructions to loop until all
[A]'s appearing in the document are replaced with similarly named autotext
entries (and the only reason I'm using these statements is because it's the
only way I know how to get the darn thing to loop)
I know all of you have been trying to help me by giving me other suggestions
(but it's not accomplishing what I need to get done) but the code I've come
up with does accomplish it. I just need something like
Keep repeating the instructions below
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[AB]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"AUTOTEXT [AB] ", PreserveFormatting:=False
Until there are no more to replace then go to the next set of instructions
following this one
I know there are Whiles and Wends but have tried to fool around with these
but can't seem to get them to work. I just need someone to get these
instructions to loop without use a counter. ?????????