Something like this perhaps:
Sub ScratchMacro()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "##"
While .Execute
oRng.Delete
oRng.Fields.Add oRng, wdFieldDocVariable, """Your Variable Name""",
True
Wend
End With
End Sub
> Group,
> I am testing code that will find text such as "##" and replace it with a
[quoted text clipped - 33 lines]
> Using MSOFFICE 2003.
> Diane
Diane - 11 Nov 2006 14:33 GMT
Greg,
Many thanks for your example. I finally had a chance to try this and it is
almost working, I'm stuck in a loop, I'm not clear as to how to have it move
on to my next find, it is finding my first text, but then it repeats the
while loop. My end result, it replaces only the first "*" and adds many
docvariables at that same position.
orng = oWord.ActiveDocument.Range
With orng.Find
.ClearFormatting()
.Text = "*"
Loop--> While .Execute
orng.Delete()
orng.Fields.Add(orng,
Word.WdFieldType.wdFieldDocVariable, "abc", True)
End While
End With
Thanks,
Diane
> Something like this perhaps:
> Sub ScratchMacro()
[quoted text clipped - 47 lines]
> > Using MSOFFICE 2003.
> > Diane
Diane - 11 Nov 2006 19:28 GMT
Thank you Greg, found my problem, your example was great!!
Diane
> Something like this perhaps:
> Sub ScratchMacro()
[quoted text clipped - 47 lines]
> > Using MSOFFICE 2003.
> > Diane