【发布时间】:2017-09-22 06:21:57
【问题描述】:
我有一个打开的 Word 文档,其中包含一堆书签,每个书签都包含之前从 Excel 导出的 Excel 表格的内嵌图像。
现在,我需要更新 Word 文档中的表格,因为它们在 Excel 中发生了变化。
我这样做的方法是将 Excel 中的表格名称与 Word 中的书签名称相匹配。如果它们相等,我想将 Word 中的现有图像替换为当前图像。
这是我目前的代码:
Sub substituir()
Set WordApp = GetObject(class:="Word.Application")
Set DocumentoDestino = WordApp.ActiveDocument
For Each folha In ThisWorkbook.Worksheets
If folha.Visible Then
'loop all excel tables
For Each tabela In folha.ListObjects
tabela.Name = Replace(tabela.Name, " ", "")
nomeTabela = tabela.Name
For Each myBookmark In DocumentoDestino.Bookmarks
If Right(myBookmark.Name, 4) = "PGST" Then
'This is where I need help
If myBookmark.Name = nomeTabela Then
'code to clear the table already in myBookmark here
'then copy and paste tables in myBookmark
tabela.Range.Copy
myBookmark.Range.PasteSpecial link:=False, DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, DisplayAsIcon:=False
End If
End If
Next myBookmark
Next tabela
End If
Next folha
End Sub
我尝试了很多不同的方法,从删除书签并将其重新添加回其他人,但似乎没有任何效果。
在评论中:'code to clear the table already in myBookmark here我需要帮助。
【问题讨论】: