Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a text document where image paths are written explicitly such as:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 


I am looking for some macro script that will look for these file paths in the document and insert these images into the Word document.

Do you know such a script?

share|improve this question

I recorded a macro and changed it a bit in order to make it generic. It does what I need. Here is the script:

Sub replace_path_with_image()
' replace_path_with_image Macro
    With Selection.Find
        .Text = "c:\users"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Dim Sel As Selection
    Set Sel = Application.Selection
    Dim FilePath As String
    If Sel.Type <> wdSelectionIP Then
        FilePath = Sel.Text
    End If
    Selection.InlineShapes.AddPicture FileName:= _
        FilePath _
        , LinkToFile:=False, SaveWithDocument:=True
    Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.