我在工作表上有多个公司徽标,我试图选择并插入我生成的Word文档,因为工作簿是共享的,我不想引用驱动器或集中位置(我已经注释掉了)下面,这是有效的)。我不知道如何将pic作为字符串引用?使用工作簿中的图片/形状替换文件位置。有什么想法吗?
Dim CompanyLogo As String
Dim Pic As Shape
Dim shp As Object
On Error GoTo ERRHANDLER
INSHEADERLOGO = True
'Select from multiple logos based on user selection
'CompanyLogo = "C:\Users\Me\Dropbox\Pics\My Logo.jpg"
TWB.Activate
IWS.Activate
For Each Pic In ActiveSheet.Shapes
If Pic.Type = msoPicture Then
If Pic.Name = WD.PicName Then
Debug.Print Pic.ID
Debug.Print Pic.Name ' neither worked
CompanyLogo = Pic.Name
Set shp = DOC.sections.item(1).headers(1).Shapes.AddPicture(CompanyLogo)
End If
End If
Next Pic
答案 0 :(得分:0)
通过将pic引用为字符串不确定您的意思,但这是我刚刚尝试的内容,它为我提供了您正在寻找的所有信息。希望这会有所帮助:
Sub PicThing()
Dim oPic As Shape
Dim oWS As Worksheet: Set oWS = ThisWorkbook.Worksheets(1)
For Each oPic In oWS.Shapes
MsgBox "Type: " & oPic.Type & vbCrLf & "Name: " & oPic.Name & vbCrLf & "ID: " & oPic.ID
Next
End Sub