Excel 使用VBA插入图像-(不链接到图像)
我有一些VBA代码,可以将图像添加到电子表格中,这一切都很好,但当我将其发送到外部时,显然链接不再起作用,因为其他用户不在我的网络上 如何修改此代码以将实际图像插入电子表格而不是链接到电子表格 我知道excel文件在这种情况下可能会变大,但它们是我插入的20KB的小缩略图Excel 使用VBA插入图像-(不链接到图像),excel,vba,Excel,Vba,我有一些VBA代码,可以将图像添加到电子表格中,这一切都很好,但当我将其发送到外部时,显然链接不再起作用,因为其他用户不在我的网络上 如何修改此代码以将实际图像插入电子表格而不是链接到电子表格 我知道excel文件在这种情况下可能会变大,但它们是我插入的20KB的小缩略图 Private Sub Worksheet_Change(ByVal Target As Range) Dim myPict As Picture Dim PictureLoc As String On Error
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myPict As Picture
Dim PictureLoc As String
On Error GoTo EH
Application.EnableEvents = False
If Target.Column = 1 Then
'Pictures.Delete
PictureLoc = "\\ca-sbs-01\t\Shared\ExcelImages\" & Target.Value2 & ".jpg"
With Target.Offset(, 1)
Set myPict = ActiveSheet.Pictures.Insert(PictureLoc)
.RowHeight = myPict.Height
myPict.Top = .Top
myPict.Left = .Left
myPict.Placement = xlMoveAndSize
End With
End If
EH:
Application.EnableEvents = True
End Sub
您可以像这样使用
Shapes.Addpicture
方法:
Dim myPict as Shape
With Target.Offset(, 1)
Set myPict = Me.Shapes.AddPicture(Filename:=PictureLoc, linktofile:=msoFalse, savewithdocument:=msoCTrue, Left:=.Left, Top:=.Top, Width:=-1, Height:=-1)
.RowHeight = myPict.Height
End With
myPict.Placement = xlMoveAndSize
使用
ActiveSheet.Shapes.AddPicture
而不是Pictures.Insert
@SiddharthRout我太懒了,无法查找其余的参数: