从Excel中replaceWord书签中的图像

我有一个打开的Word文档,有一堆书签,每个书签都有一个以前从Excel导出的Excel表格的内嵌图像。

现在,我需要更新Word文档中的表格,因为它们在Excel中已更改。

我这样做的方式是将Excel中的表名与Word中的书签名称进行匹配。 如果它们相等,我想用现有的replaceWord中现有的图像。

这是我的代码到目前为止:

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我需要帮助。

在下面的代码中,我试图包含您的项目可能需要的语法。

 Private Sub TestMark() Dim Mark As String Dim Rng As Range Dim ShpRng As Range Mark = "Text1" With ActiveDocument If .Bookmarks.Exists(Mark) Then Set Rng = .Bookmarks(Mark).Range If Rng.InlineShapes.Count Then Set ShpRng = Rng.InlineShapes(1).Range With ShpRng Debug.Print .Start, .End End With End If End If End With End Sub 

当然,一旦你知道范围的开始和结束,你可以操纵它,意味着删除并replace它。

我想你可能会使用InlineShape的Caption属性来查找和解决它。