我想使用VBA将图片导入Word。图片需要导入书签然后缩放。
我尝试使用以下代码,但代码存在一些问题。图片未导入书签,我无法缩放图片。有什么建议我做错了吗?
Sub ImportReport()
ActiveDocument.GoTo What:=wdGoToBookmark, Name:="bm1"
Selection.InlineShapes.AddPicture FileName:= _
"File_path_to_the_PNG_file", _
LinkToFile:=False, _
SaveWithDocument:=True
', _
'ScaleWidth:=100, _
'ScaleHeight:=100
InlineShapes.Item(1).ScaleHeight = 100
Shapes.Item(1).ScaleWidth = 100
End Sub
答案 0 :(得分:0)
这就是我最后所做的。我有18张图片要导入。我已经在word文件中创建了书签。
Sub ImportScaleWrap()
Dim ImagePath As String
Dim FileName As String
Dim i As Integer
ImagePath = "IMAGE_PATH"
FileName = "GENERIC_PART_OF_FILE_NAME"
Dim RiskPic As InlineShape
For i = 1 To 18
Set RiskPic = ActiveDocument.Bookmarks("bm" & i).Range.InlineShapes.AddPicture(FileName:=ImagePath & FileName & i & ".png", LinkToFile:=False, SaveWithDocument:=True)
RiskPic.ScaleHeight = 100
RiskPic.ScaleWidth = 100
Dim RiskPicType As Shape
Set RiskPicType = RiskPic.ConvertToShape
RiskPicType.WrapFormat.Type = wdTopBottom
Next i
End Sub