在特定位置插入图像时出现问题
Problem inserting Image at a specific position
我一直在使用单词 VBA Shapes.AddPicture 方法(如 Add image to Word document at specified position 中)在文档的特定位置插入 Png(以前用 [= 找到的文本附近) 19=]...) 多年来一切都没有问题,但现在,没有任何变化(也没有在文档或代码中)图像已经开始进入左上角,我找不到原因。 ..
有人知道在上次更新中是否有什么变化或发生了什么吗?
我使用的是正确更新的 365 版本,我的代码是:
Dim mySignatureShape As shape
Dim myImagePath as string
Selection.Find.Execute FindText:=" Text to find Here "
Selection.Collapse
myLeft = "-25"
myTop = "-49"
myImagePath = "Full Image Path Here"
Set mySignatureShape = ActiveDocument.Shapes.AddPicture(Filename:=myImagePath, LinkToFile:=False, _
SaveWithDocument:=True,
Anchor:=Selection.Range, _
Width:="275", Height:="150", _
Left:=myLeft, Top:=myTop)
您的代码缺少任何内容来告诉 Word 将图像放置在与找到的文本相关的位置。因此,除非文本本身靠近页面顶部,否则它永远无法将图像 'near' 定位到该文本。尝试:
Application.ScreenUpdating = False
Dim mySignatureShape As Shape
Dim myImagePath As String
Dim myLeft As Long, myTop As Long
myImagePath = "Full Image Path"
With Selection
.Find.Execute FindText:="Text to find"
.Collapse wdCollapseStart
myLeft = -25 + .Information(wdHorizontalPositionRelativeToPage)
myTop = -49 + .Information(wdVerticalPositionRelativeToPage)
Set mySignatureShape = ActiveDocument.Shapes.AddPicture(FileName:=myImagePath, LinkToFile:=False, _
SaveWithDocument:=True, Anchor:=.Range, Width:=275, Height:=150, Left:=myLeft, Top:=myTop)
End With
Application.ScreenUpdating = True
我一直在使用单词 VBA Shapes.AddPicture 方法(如 Add image to Word document at specified position 中)在文档的特定位置插入 Png(以前用 [= 找到的文本附近) 19=]...) 多年来一切都没有问题,但现在,没有任何变化(也没有在文档或代码中)图像已经开始进入左上角,我找不到原因。 ..
有人知道在上次更新中是否有什么变化或发生了什么吗?
我使用的是正确更新的 365 版本,我的代码是:
Dim mySignatureShape As shape
Dim myImagePath as string
Selection.Find.Execute FindText:=" Text to find Here "
Selection.Collapse
myLeft = "-25"
myTop = "-49"
myImagePath = "Full Image Path Here"
Set mySignatureShape = ActiveDocument.Shapes.AddPicture(Filename:=myImagePath, LinkToFile:=False, _
SaveWithDocument:=True,
Anchor:=Selection.Range, _
Width:="275", Height:="150", _
Left:=myLeft, Top:=myTop)
您的代码缺少任何内容来告诉 Word 将图像放置在与找到的文本相关的位置。因此,除非文本本身靠近页面顶部,否则它永远无法将图像 'near' 定位到该文本。尝试:
Application.ScreenUpdating = False
Dim mySignatureShape As Shape
Dim myImagePath As String
Dim myLeft As Long, myTop As Long
myImagePath = "Full Image Path"
With Selection
.Find.Execute FindText:="Text to find"
.Collapse wdCollapseStart
myLeft = -25 + .Information(wdHorizontalPositionRelativeToPage)
myTop = -49 + .Information(wdVerticalPositionRelativeToPage)
Set mySignatureShape = ActiveDocument.Shapes.AddPicture(FileName:=myImagePath, LinkToFile:=False, _
SaveWithDocument:=True, Anchor:=.Range, Width:=275, Height:=150, Left:=myLeft, Top:=myTop)
End With
Application.ScreenUpdating = True