|
excel表中图片引用 ›
本帖最后由 joyark 于 2011-6-15 03:20 编辑
回复 nantong718 的帖子
參考4樓例子
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 And Target.Column = 2 And Target.Row > 2 Then
For Each im In ActiveSheet.Pictures
If im.Top = Target(1, 2).Top Then im.Delete: Exit For
Next
pic = ThisWorkbook.Path & "\照片\" & Target & ".jpg"
If Dir(pic) = "" Then Exit Sub
Me.Pictures.Insert(pic).Select '当前文件所在目录下以单元内容为名称的.jpg图片
With Selection
ta = Target(1, 3).MergeArea.Height '(合并)单元高度
tb = Target(1, 3).MergeArea.Width '(合并)单元宽度
tc = .Height '图片高度
td = .Width '图片宽度
tm = Application.WorksheetFunction.Min(ta / tc, tb / td) '单元与图片之间长宽差异比例的最小值
.Height = tc * tm '按比例调整图片宽度
.Width = td * tm '按比例调整图片高度
.Top = Target(1, 3).Top + (ta - .Height) / 2 '垂直居中:
.Left = Target(1, 3).Left + (tb - .Width) / 2 '水平居中:
End With
Target.Select
End If
End Sub
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|