VBA办公工具 自动对齐 Shape 位置及大小

<?xml version="1.0" encoding="UTF-8" standalone="no"?>



Code
myShape.AutoShapeType

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
    Cells.ColumnWidth = 2
    Cells.RowHeight = 13.8 * 150 / 138
Dim myShape As Shape
Dim L_Top As Long
Dim L_Left As Long
L_Top = (Range("a1").Offset(100, 100).Top - Range("a1").Top) / 100
L_Left = (Range("a1").Offset(100, 100).Left - Range("a1").Left) / 100

Dim TheResult As Boolean
For Each myShape In ActiveSheet.Shapes
    TheResult = False
    TheResult = TheResult Or (myShape.AutoShapeType = 5) '圆角矩形
    TheResult = TheResult Or (myShape.AutoShapeType = 7) '三角形
    TheResult = TheResult Or (myShape.AutoShapeType = 33) '向右箭头填充
    TheResult = TheResult Or (myShape.AutoShapeType = 9) '椭圆

    If TheResult Then
        myShape.Top = Int(myShape.Top / L_Top) * L_Top
        myShape.Left = Int(myShape.Left / L_Left) * L_Left
        '一定是先 移动 然后改变 Shape 大小
        myShape.Width = Int(myShape.Width / L_Left) * L_Left
        myShape.Height = Int(myShape.Height / L_Top) * L_Top
    End If
Next

If Target.Address = Range("a1").Address Then
    Range("a2").Select
    For Each myShape In ActiveSheet.Shapes
        If myShape.AutoShapeType = 5 Then '圆角矩形
        ElseIf myShape.AutoShapeType = -2 Then '细小箭头
        ElseIf myShape.AutoShapeType = 7 Then '三角形
        ElseIf myShape.AutoShapeType = 33 Then '向右箭头填充
        ElseIf myShape.AutoShapeType = 9 Then '椭圆
        Else
            myShape.Select
            MsgBox myShape.AutoShapeType
        End If
    Next
End If

ActiveWindow.DisplayGridlines = (Range("a2").Value = "")
Application.EnableEvents = True
End Sub

Code
重点

<?xml version="1.0" encoding="UTF-8" standalone="no"?>



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值