|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 图片点击缩放()
Dim shp As shape
Dim LastShp As Object
On Error Resume Next
' 遍历当前工作表的所有形状
For Each shp In ActiveSheet.Shapes
' 检查形状是否为OLE对象或图片
If shp.Type = msoLinkedOLEObject Or shp.Type = msoPicture Then
' 如果形状的OnAction属性为空,则设置为"图片点击缩放"
If shp.OnAction = vbNullString Then
shp.OnAction = "图片点击缩放"
End If
' 如果形状的名称与调用者(即当前活动单元格)的形状名称相同
If shp.Name = ActiveSheet.Shapes(Application.Caller).Name Then
' 如果形状的AlternativeText为空,则记录其原始高度和宽度
If shp.AlternativeText = vbNullString Then
If Not LastShp Is Nothing Then
' 还原上一个图片的大小
LastShp.Height = Split(LastShp.AlternativeText, Chr(28))(0)
LastShp.Width = Split(LastShp.AlternativeText, Chr(28))(1)
LastShp.AlternativeText = vbNullString
End If
' 锁定纵横比并记录图片的原始尺寸
shp.LockAspectRatio = msoTrue
shp.AlternativeText = shp.Height & Chr(28) & shp.Width
' 缩放图片
shp.Height = shp.Height * 1.8 ' 调整此处的倍数以改变缩放比例
shp.Width = shp.Width * 1.8
shp.ZOrder msoBringToFront
' 记录当前图片作为上一个图片
Set LastShp = shp
Else
' 如果已经记录了图片的原始尺寸,则还原图片大小
shp.Height = Split(shp.AlternativeText, Chr(28))(0)
shp.Width = Split(shp.AlternativeText, Chr(28))(1)
shp.AlternativeText = vbNullString
End If
End If
End If
Next shp
End Sub |
|