我可以在不取消超链接的情况下取消链接输出 Word 邮件合并中的图片字段吗

Can I unlink picture fields in output Word mail merge without unlinking hyperlinks

我正在从 MS Access VBA 执行 Word 邮件合并。该文档同时包含图片和超链接,它们是根据邮件合并源动态生成的table。

为了转换图片,我在执行邮件合并后使用objWord.Fields.Unlink,但我最近添加了一个动态超链接,代码也删除了那些链接。

要插入图片,我使用 { INCLUDEPICTURE { IF TRUE "{PicturePathFromMailmerge}" } \d }

要插入超链接,我有 { HYPERLINK { MERGEFIELD LinkFieldFromMailmerge } * MERGEFORMAT }

我的代码是:

    objWORD.MailMerge.Execute

    Set objNEW = objWORD.Application.ActiveDocument

    objNEW.Fields.Unlink

所以,相当随意,但我没有太多使用 VBA 来处理 Word 文档的经验。

如何删除图片链接而不是超链接?图片包含在 table 中,所以这可能会有所帮助,如果您可以 运行 选择每个 table 并取消链接内容的代码?

简单的答案是您不能使用字段编码来做到这一点。需要一个宏。例如,作为截取 'Edit Individual Documents' 进程的独立 Word 宏:

Sub MailMergeToDoc()
Application.ScreenUpdating = False
Dim i As Long
ActiveDocument.MailMerge.Execute
With ActiveDocument
  For i = .Fields.Count To 1 Step -1
    If .Fields(i).Type <> wdFieldHyperlink Then .Fields(i).Unlink
  Next
End With
Application.ScreenUpdating = True
End Sub