尝试使用 VBA 在 Word table 中的文本后插入图像

Attempting to insert an image after the text within a Word table using VBA

我在 Word 中有一个 table,每个单元格中包含一些文本。我想在文本末尾的单元格中插入文件中的图像。目前我只会在文字前插入图片

下图显示了一个基本的 table,第一个单元格中有一些文本:

然后我 运行 一个基本宏,用于将文件中的特定图像插入第一个单元格:

Sub InsertImageIntoCell()
    ActiveDocument.Tables(1).Rows(1).Cells(1).Range.InlineShapes.AddPicture _
    FileName:="C:\Data\tree.png", linktofile:=False, savewithdocument:=True
End Sub

在宏 运行 之后,我最终在文本左侧出现了一张图片:

任何人都可以提供一些关于如何将图像插入到预先存在的文本右侧的见解吗?

在 Timothy 的评论之后,我设法做了一些研究并提出了解决方案。

这是我的 VBA 代码:

Sub InsertImageIntoCell()
    With ActiveDocument
        Set myRange = .Tables(1).Rows(1).Cells(1).Range
        myRange.Start = myRange.End - 1
        
        .Tables(1).Rows(1).Cells(1).Range.InlineShapes.AddPicture _
        FileName:="C:\Data\tree.png", linktofile:=False, _
        savewithdocument:=True, Range:=myRange
    End With
End Sub

这当然可能不是最好的解决方案,但对我来说效果很好。即它现在在单元格中的文本之后插入图像。

这是 运行 宏之前的 Table:

在 运行 宏之后,又是这样:

更简单:

Sub InsertImageIntoCell()
With ActiveDocument
  .InlineShapes.AddPicture FileName:="C:\Data\tree.png", LinkToFile:=False, _
    SaveWithDocument:=True, Range:=.Tables(1).Cell(1, 1).Range.Characters.Last
End With
End Sub