# Word 如何将链接的图像转换为嵌入？

如果是网页等形式，或者本身图片以引用的方式插入，则除了 docx 文档外还需要给出额外的图片文件，并保证路径可用，否则就会如下图所示：

![1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1651249890686/k7kDKgGuu.png align="left")

这种情况下，我们可以使用VBA代码将链接的图像转换为嵌入式图像。

1. 打开Word文档，同时保证链接图像可以正常显示。 按 Alt + F11 键打开 Microsoft Visual Basic应用程序 窗口。
2. 插入模块，粘贴下方的 VBA 代码并执行。

![2.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1651249901730/U6fzhMrnp.png align="left")


```
Sub convert_all_inline_shapes()
    Dim xIShape As InlineShape
    For Each xIShape In ActiveDocument.InlineShapes
        With xIShape
            If .Type = wdInlineShapeLinkedPicture Then
                .LinkFormat.SavePictureWithDocument = True
                .LinkFormat.BreakLink
            End If
        End With
    Next
End Sub
``` 

