|
楼主 |
发表于 2018-3-27 19:06
|
显示全部楼层
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$8" Then
Dim pic As Object, PicPathAndName As String, PicFolder As String
Dim PicT As Integer, PicL As Integer, PicH As Integer, PicW As Integer
'图片文件夹名称
PicFolder = "图片文件夹"
'所选图片路径
PicPathAndName = ThisWorkbook.path & "\" & PicFolder & "\" & Range("B8") & ".jpg"
Set pic = ActiveSheet.Shapes("图片 1")
'原图片的位置和大小
With pic
PicT = .Top
PicL = .Left
PicH = .Height
PicW = .Width
End With
'删除原图片
pic.Delete
'插入所选图片
Set pic = ActiveSheet.Shapes.AddPicture(Filename:=PicPathAndName, LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=PicL, Top:=PicT, Width:=PicW, Height:=PicH)
'设置图片名称
pic.name = "图片 1"
End If
Set pic = Nothing
End Sub |
|