Replace each instance of the text string Document One with the contents of a file called c:\test\Doc1.doc

Article contributed by Bill Coan

Sub ReplaceTagWithFile()

Selection.HomeKey unit:=wdStory

With Selection.Find

    .ClearFormatting
    .Text = "Document One"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = True
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False

    Do While .Execute()
        Selection.InsertFile _
        FileName:="c:\test\Doc1.doc", Range:="", _
        ConfirmConversions:=False, _
        Link:=False, _
        Attachment:=False
    Loop

End With

End Sub


Click to view Terms of Use page

Click to view Disclaimer page