Thanks, Klaus - I almost got it working, but am still having some problems.
I had to change the wild cards a bit, but this code can now identify the
whole tag and parse out the file name...
Selection.Find.ClearFormatting
With Selection.Find
.Text = "\<insertDocument\>*\<\/\>"
.Replacement.Text = "tag removed "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
End With
While Selection.Find.Execute
' in case you need the selection, including tags, later:
Set oldSelection = Selection.Range.Duplicate
posStart = InStr(2, Selection.Text, ">")
posEnd = InStr(posStart, Selection.Text, "<") - 1
ActiveDocument.Range(Selection.Start + posStart, _
Selection.Start + posEnd).Select
documentname = Selection.Text
MsgBox documentname, , "Insert tag found"
Wend
The document name is correct. However, the replacement does not appeart to
work, plus, it only finds the first occurance of the tag and appears to stop.
1) How do I get the replacement to work? (eventually I will replace with
blank)
2) How do I get it to process all tags found?
Here is the sample data...
{\rtf1
\outlinelevel0 \b\f1\fs32 First Heading \b0
\par
\par
\outlinelevel1 \b\f2\fs28\ul Second Heading\b0\ul0
\par
\par \outlinelevel2 \b\f3\fs26 Third Heading \b0
\par
\par\fs20\outlinelevel
Just text
\par
<insertDocument>DiagramOneTest.vsd</>
\par
\par some more text
\par and yet more text
\par
<insertDocument>diagramTwoTest.vsd</>
\par last text
}
Klaus Linke - 31 Jan 2005 21:07 GMT
Hi Cris,
You need a "Selection.Collapse(wdCollapseEnd)" right before the "Wend", so you
don't match the same text again and again.
The code as it is also doesn't do any replacement.
If you want to delete the Visio file name, you can set Selection.Text="" (...
where it's currently displaying the MsgBox).
As I said, I don't know the code for inserting a Visio file at that point, given
its file name. Maybe you can figure out something from the macro recorder.
> {\rtf1
> \outlinelevel0 \b\f1\fs32 First Heading \b0
Did the text paste as RTF only in your newsgroup post, or do you edit RTF files
directly by opening them as text files?
If the latter, it's probably a risky business for this kind of thing.
You'd need the replacement text (inserted Visio file) exactly right, else you
easily corrupt the document.
Greetings,
Klaus
> Thanks, Klaus - I almost got it working, but am still having some problems.
> I had to change the wild cards a bit, but this code can now identify the
[quoted text clipped - 51 lines]
> \par last text
> }