Share via

Absolute path in a word document

Anonymous
2025-04-01T15:12:49+00:00

After running a report in another program creating a rtf document I am having several absoute paths to images on my computer in the document which I then save as a .docx document. Would it be possible to address all these absolute paths to insert the images into the location of the paths without doing one at a time?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Paul Edstein 82,861 Reputation points Volunteer Moderator
2025-04-02T22:08:52+00:00

The reason the code I posted did not work is because is because it was written for the only example you gave - which is for filenames with 3-character lower-case extensions. Some graphics editors also output files with 4-character extensions, like .jpeg. To capture all alphabetic extensions, you could use a Find expression like:

.Text = "C:*.[A-Za-z]@>"

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Jay Freedman 207.7K Reputation points Volunteer Moderator
2025-04-02T20:37:14+00:00

The part of the search expression that looks for the file's extension is

[a-z]{3}

which looks for three lower-case letters. Because wildcard searches are always case-sensitive, your upper-case extension isn't recognized. Instead, use

[A-Za-z]{3}

which will recognize any combination of upper-case and lower-case letters.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

5 additional answers

Sort by: Most helpful
  1. John Korchok 232.8K Reputation points Volunteer Moderator
    2025-04-01T15:49:13+00:00

    That should be possible with a VBA macro. A Find operation could find each hyperlink, get the path, then use that path to insert the image into the document.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2025-04-01T22:18:28+00:00

    You could use a macro like:

    Sub Demo()
    
    Application.ScreenUpdating = False
    
    Dim StrTxt As String
    
    With ActiveDocument.Range
    
      With .Find
    
        .ClearFormatting
    
        .Replacement.ClearFormatting
    
        .MatchWildcards = True
    
        .Text = "C:*.[a-z]{3}>"
    
        .Replacement.Text = ""
    
        .Wrap = wdFindStop
    
        .Forward = True
    
        .Format = False
    
      End With
    
      Do While .Find.Execute
    
        StrTxt = .Text: .Text = vbNullString
    
        .InlineShapes.AddPicture StrTxt, True, True, .Duplicate
    
      Loop
    
    End With
    
    Application.ScreenUpdating = True
    
    End Sub
    

    The above code inserts the pictures as linked images. Alternatively, to insert them as stand-alone images:

    Sub Demo() 
    
    Application.ScreenUpdating = False 
    
    Dim StrTxt As String 
    
    With ActiveDocument.Range 
    
      With .Find 
    
        .ClearFormatting 
    
        .Replacement.ClearFormatting 
    
        .MatchWildcards = True 
    
        .Text = "C:*.[a-z]{3}>" 
    
        .Replacement.Text = "" 
    
        .Wrap = wdFindStop 
    
        .Forward = True 
    
        .Format = False 
    
      End With 
    
      Do While .Find.Execute 
    
        StrTxt = .Text: .Text = vbNullString 
    
        .InlineShapes.AddPicture StrTxt, False, True, .Duplicate 
    
      Loop 
    
    End With 
    
    Application.ScreenUpdating = True 
    
    End Sub
    

    For PC macro installation & usage instructions, see: http://www.gmayor.com/installing\_macro.htm

    For Mac macro installation & usage instructions, see: https://wordmvp.com/Mac/InstallMacro.html

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2025-04-01T16:12:11+00:00

    There are no hyperlinks in the document, only absolute paths.

    Like: C:\Media\picture\image\234.jpg

    Was this answer helpful?

    0 comments No comments