How to Convert All Word Embedded Pictures to Linked Pictures Programmatically
🔍 WiseChecker

How to Convert All Word Embedded Pictures to Linked Pictures Programmatically

When you insert pictures directly into a Word document, the file size grows quickly, making it harder to share or collaborate. Embedded pictures store the full image data inside the .docx file, while linked pictures reference an external file and keep the document lean. This article explains how to convert every embedded picture to a linked picture using a VBA macro, saving disk space and improving document performance. You will learn the exact code to run, the prerequisites, and what to do if linking fails.

Key Takeaways: Convert Embedded Images to Linked Images via VBA

  • VBA macro in Word: Automates the process of replacing each embedded picture with a linked version using the same image file path.
  • File > Options > Trust Center > Trust Center Settings > Enable all macros: Required to run the VBA macro without security warnings.
  • InlineShapes.AddPicture method with LinkToFile:=True: Creates a linked picture that updates when the source file changes.

ADVERTISEMENT

How Embedded and Linked Pictures Work in Word

When you insert a picture by going to Insert > Pictures > This Device, Word embeds the full image data into the document. The document size increases by roughly the size of each image. This makes emailing or uploading the file slower, and editing the original image later does not update the copy in Word.

A linked picture, on the other hand, stores only the file path to the image source. The document remains small, and if you modify the source image file, Word can update the linked picture automatically (provided the link is maintained). The trade-off is that the image file must stay in the same location; if you move it, the link breaks.

Word does not offer a built-in command to batch-convert embedded pictures to linked pictures. You must use a VBA macro to replace each embedded shape with a linked version. The macro reads the original image file path from the embedded picture (if available), deletes the embedded shape, and inserts a new linked picture at the same position.

Prerequisites for Running the Macro

Before you run the conversion macro, confirm the following:

  • All embedded pictures were originally inserted from files on your computer or a network drive. Pictures copied from the web or pasted from the clipboard do not have a source file path and cannot be linked.
  • The original image files still exist at their original paths. If you moved or deleted them, the macro will fail for those pictures.
  • You have permission to run macros in Word. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and select Enable all macros. Revert this setting after you finish.

Step-by-Step Macro to Convert Embedded Pictures to Linked Pictures

Follow these steps to create and run the VBA macro. The macro processes all InlineShapes (pictures anchored to text) and Shapes (floating pictures) in the active document.

  1. Open the VBA editor
    Press Alt+F11 in Word. The Microsoft Visual Basic for Applications window opens.
  2. Insert a new module
    In the Project Explorer pane, right-click Normal or the current document project, choose Insert, then Module. A blank code window appears.
  3. Paste the macro code
    Copy the following code and paste it into the module window:
Sub ConvertEmbeddedToLinked()
    Dim shp As InlineShape
    Dim shp2 As Shape
    Dim imgPath As String
    Dim imgWidth As Single
    Dim imgHeight As Single
    Dim rng As Range
    
    Application.ScreenUpdating = False
    
    ' Process InlineShapes (pictures in line with text)
    For Each shp In ActiveDocument.InlineShapes
        If shp.Type = wdInlineShapePicture Then
            On Error Resume Next
            imgPath = shp.LinkFormat.SourcePath & "\" & shp.LinkFormat.SourceName
            If Err.Number <> 0 Then
                ' No link info; skip if embedded without source
                Err.Clear
                GoTo NextInline
            End If
            On Error GoTo 0
            
            imgWidth = shp.Width
            imgHeight = shp.Height
            Set rng = shp.Range
            shp.Delete
            
            Set shp = rng.InlineShapes.AddPicture( _
                FileName:=imgPath, _
                LinkToFile:=True, _
                SaveWithDocument:=False, _
                Range:=rng)
            shp.Width = imgWidth
            shp.Height = imgHeight
        End If
NextInline:
    Next shp
    
    ' Process floating Shapes
    For Each shp2 In ActiveDocument.Shapes
        If shp2.Type = msoPicture Then
            On Error Resume Next
            imgPath = shp2.LinkFormat.SourcePath & "\" & shp2.LinkFormat.SourceName
            If Err.Number <> 0 Then
                Err.Clear
                GoTo NextShape
            End If
            On Error GoTo 0
            
            imgWidth = shp2.Width
            imgHeight = shp2.Height
            Set rng = shp2.Anchor
            shp2.Delete
            
            Set shp2 = ActiveDocument.Shapes.AddPicture( _
                FileName:=imgPath, _
                LinkToFile:=True, _
                SaveWithDocument:=False, _
                Anchor:=rng)
            shp2.Width = imgWidth
            shp2.Height = imgHeight
        End If
NextShape:
    Next shp2
    
    Application.ScreenUpdating = True
    MsgBox "Conversion complete.", vbInformation
End Sub
  1. Run the macro
    Press F5 to run the macro, or go to Run > Run Sub/UserForm. Word processes each picture and replaces it with a linked version. A message box confirms completion.
  2. Save the document
    Press Ctrl+S to save the document. Word now stores only the image paths, not the image data. The file size should be significantly smaller.

ADVERTISEMENT

If the Macro Skips Some Pictures or Returns Errors

The macro may skip pictures or produce errors in specific scenarios. Below are the most common problems and how to resolve them.

Some pictures were not converted

Pictures pasted from the clipboard, copied from a web page, or inserted via drag-and-drop from an email do not have a source file path. The macro cannot determine where the original file resides. To convert these, you must manually re-insert each picture using Insert > Pictures > This Device and then run the macro again.

Error: Run-time error 5174 — File not found

This error means the original image file no longer exists at the stored path. Restore the file to its original location or update the path in the macro. You can check the path for a specific picture by right-clicking it, selecting Format Picture, and looking at the Alt Text tab (some metadata may show the path).

Linked pictures show a red X or broken image icon

If you move or rename the source image files after conversion, Word cannot display the linked picture. To fix this, go to File > Info > Edit Links to Files, select the broken link, and click Change Source to point to the new file location.

Comparison: Embedded vs Linked Pictures in Word

Item Embedded Picture Linked Picture
Document file size Large (includes full image data) Small (stores only file path)
Image source requirement None (image is self-contained) Original file must remain accessible
Update when source changes Manual re-insertion required Automatic via Edit Links to Files
Portability Works anywhere without extra files Broken if source files are moved
Batch conversion method VBA macro (this article) VBA macro (this article)

You can now convert all embedded pictures to linked pictures in a single macro run, reducing document size and enabling automatic image updates. After conversion, consider using File > Info > Edit Links to Files to verify that all links are valid. For advanced control, modify the macro to skip pictures below a certain size or to log skipped images to a separate document.

ADVERTISEMENT