我有这样的代码:
Selection.InlineShapes.AddPicture FileName:=path & "\" & "image.png", LinkToFile:=False, SaveWithDocument:=True
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.InlineShapes.Item(1).ScaleHeight = 80
Selection.InlineShapes.Item(1).ScaleWidth = 80但是出现了一条5941错误消息:
运行时错误'5941‘集合的请求成员不存在。
我想设置特定的高度和宽度。
我怎么才能修好它?
发布于 2017-10-24 03:10:57
哦(最新的答复)..。请试一试,(文字后面的图片的评论令人困惑.)。现在的问题似乎是,当您更改段落格式时,实际上取消了图像的选择。这可以通过在添加图像之前更改段落对齐来解决。可以这样做:
Sub ap()
Dim imgPath As String
imgPath = imgPath & "image.png"
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Dim myIlsh As InlineShape
Set myIlsh = Selection.InlineShapes.AddPicture(FileName:=imgPath, LinkToFile:=False, SaveWithDocument:=True)
myIlsh.ScaleHeight = 80
myIlsh.ScaleWidth = 80
Set myIlsh = Nothing
End Sub如果您确实有与文本不一致的图像,您应该能够用以下方法修复它们:
Sub resizeImage()
Dim iLoop As Long
For iLoop = 1 To ActiveDocument.Shapes.Count
ActiveDocument.Shapes(iLoop).Select
If MsgBox("resize shape & convert to inline?", vbYesNo) = vbYes Then
If ActiveDocument.Shapes(iLoop).WrapFormat.Type <> wdWrapInline Then
ActiveDocument.Shapes(iLoop).ConvertToInlineShape
End If
ActiveDocument.Shapes(iLoop).ScaleHeight 0.8, msoTrue
ActiveDocument.Shapes(iLoop).ScaleWidth 0.8, msoTrue
End If
Next iLoop
End Sub发布于 2017-10-23 11:28:25
您可能想看看这。以下是该网站的评论:
基本要素: 使用关联形状容器的.ScaleHeight和.ScaleWidth属性调整图片的大小。此属性确定要缩放图像的相对于原始图片大小的百分比大小。 示例: 以下代码将图片高度调整为原始图片高度的90%:
InlineShapes.Item(1).ScaleHeight = 90
或者,您可以在创建图像时更改大小:
ActiveDocument.Shapes.AddPicture FileName:=path & "\" & "image.png", _
LinkToFile:=False, _
SaveWithDocument:=True, _
Left:=-0, _
Top:=0, _
Anchor:=Selection.Range, _
Width:=50, _
Height:=50https://stackoverflow.com/questions/46887599
复制相似问题