你好,请帮忙修改一下代码,希望图片能自动缩放在单元格大小里面。
您好!下面的代码,可以实现在C4(合并的)中输入,在T11:AB18合并的单元格里显示图片,但图片有大有小,请帮忙看一下能修改吗?希望能自动缩放,谢谢!PrivateSu...
您好!下面的代码,可以实现在C4(合并的)中输入,在T11:AB18合并的单元格里显示图片,但图片有大有小,请帮忙看一下能修改吗?希望能自动缩放,谢谢!
Private Sub Worksheet_Change(ByVal Target As Range)
For Each a In ActiveSheet.Pictures
a.Delete
Next
On Error Resume Next
If Target.Address = "$C$4" Then
Dim fso, f, shp As Object
Dim rgTL As Range
Dim pname As String
pname = "c:\1\" & Range("c" & Target.Row).Value & ".jpg"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(pname) Then
For Each shp In ActiveSheet.Shapes
Set rgTL = shp.TopLeftCell
If rgTL.Row = IIf(Target.Row = 2, 1, 11) And rgTL.Column = 1 Then shp.Delete
Next
Set rgTL = Range("t" & IIf(Target.Row = 2, 1, 11))
Set shp = ActiveSheet.Pictures.Insert(pname)
shp.ShapeRange.Height = Range("t11:ab18").Height
shp.Left = Range("t11:ab18").Left
shp.Top = Range("t11:ab18").Top
Else
MsgBox "不存在此名称的图片!"
GoTo e
End If
End If
e:
Set fso = Nothing
End Sub 展开
Private Sub Worksheet_Change(ByVal Target As Range)
For Each a In ActiveSheet.Pictures
a.Delete
Next
On Error Resume Next
If Target.Address = "$C$4" Then
Dim fso, f, shp As Object
Dim rgTL As Range
Dim pname As String
pname = "c:\1\" & Range("c" & Target.Row).Value & ".jpg"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(pname) Then
For Each shp In ActiveSheet.Shapes
Set rgTL = shp.TopLeftCell
If rgTL.Row = IIf(Target.Row = 2, 1, 11) And rgTL.Column = 1 Then shp.Delete
Next
Set rgTL = Range("t" & IIf(Target.Row = 2, 1, 11))
Set shp = ActiveSheet.Pictures.Insert(pname)
shp.ShapeRange.Height = Range("t11:ab18").Height
shp.Left = Range("t11:ab18").Left
shp.Top = Range("t11:ab18").Top
Else
MsgBox "不存在此名称的图片!"
GoTo e
End If
End If
e:
Set fso = Nothing
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询