VBA Word 宏选择插入的形状

VBA Word Macro selecting inserted shape

我想要一个简单的 VBA 宏,它可以插入图片然后更改其高度和宽度。它第一次工作 运行。但是,用户可以通过 运行 多次使用宏来添加多张图片,我的问题是宏插入了下一张图像,但随后调整了文档中已有图像的大小,而不是刚刚插入的图像。我本以为 .count 会 return 最后一张图片(即刚刚插入的图片)看来 'Set myImage line' 没有引用刚刚插入的图片。

欢迎任何帮助。下面的代码。

格雷格

ActiveDocument.Shapes.AddPicture Anchor:=Selection.Range, FileName:= _
    "c:\mydir\carp3d.tif", LinkToFile:=False, SaveWithDocument:=True
' get last inserted image
Set myImage = ActiveDocument.Shapes(ActiveDocument.Shapes.Count)
myImage.Select
myImage.LockAspectRatio = msoTrue
myImage.LockAspectRatio = msoTrue
myImage.Height = 180#
myImage.Width = 124.55

Shapes.AddPicture returns 您应该捕获的 Shape 对象:

Set myImage = ActiveDocument.Shapes.AddPicture(....)

myImage.LockAspectRatio = msoTrue
' and so on