|
楼主 |
发表于 2010-7-15 16:25
|
显示全部楼层
研究了一下前人的经验。最后加入这个代码了。可以实现了。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub '如果选择一个区域时,退出程序
Dim cFile$, oShape As Shape, nW, nH '声明变量
Application.ScreenUpdating = False '禁止屏幕刷新
Application.EnableEvents = False
On Error Resume Next
Set oShape = Me.Shapes("t_" & Target.Address(0, 0))
If Not oShape Is Nothing Then Exit Sub '如果存在图片时,退出程序
If ThisWorkbook.Application.Dialogs(342).Show Then '插入图片
With Selection
.Name = "t_" & Target.Address(0, 0) '重命名
nW = Target.Width / .Width '缩放比例
nH = Target.Height / .Height
If nW < nH Then '以宽度为标准缩放
.ShapeRange.IncrementTop (Target.Height - .Height * nW) / 2
.ShapeRange.ScaleWidth nW, 0, 0
.ShapeRange.ScaleHeight nW, 0, 0
Else '以高度为标准缩放
.ShapeRange.IncrementLeft (Target.Width - .Width * nH) / 2
.ShapeRange.ScaleWidth nH, 0, 0
.ShapeRange.ScaleHeight nH, 0, 0
End If
End With
Target.Activate
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
==============================================================
但是如何限定只在B,C两列才是插入图片。 其他的不要加载这个vba? |
|