51 lines
1.7 KiB
QBasic
51 lines
1.7 KiB
QBasic
Attribute VB_Name = "Common_Shape"
|
|
Option Explicit
|
|
|
|
' ================= 通用排版引擎(仅调整位置) =================
|
|
|
|
Public Sub AlignIconsByCenter(sheetName As String, anchorAddr As String, _
|
|
iconArr As Variant, gapPt As Double)
|
|
Dim ws As Worksheet
|
|
Dim anchor As Range
|
|
Dim shp As Shape
|
|
Dim i As Long
|
|
Dim shapeCount As Long
|
|
|
|
On Error Resume Next
|
|
Set ws = ThisWorkbook.Worksheets(sheetName)
|
|
On Error GoTo 0
|
|
If ws Is Nothing Then Exit Sub
|
|
|
|
Set anchor = ws.Range(anchorAddr)
|
|
shapeCount = UBound(iconArr) - LBound(iconArr) + 1
|
|
|
|
' 第一个图标左边对齐B3左边
|
|
Dim curX As Double: curX = anchor.Left
|
|
Dim prevX As Double: prevX = 0
|
|
Dim cy As Double: cy = anchor.Top + anchor.Height / 2
|
|
|
|
Application.ScreenUpdating = False
|
|
For i = LBound(iconArr) To UBound(iconArr)
|
|
Set shp = ws.Shapes(iconArr(i))
|
|
shp.Placement = xlFreeFloating
|
|
shp.Left = curX
|
|
shp.Top = cy - shp.Height / 2
|
|
If i = LBound(iconArr) Then
|
|
Debug.Print iconArr(i) & ": left=" & curX & ", width=" & shp.Width
|
|
Else
|
|
Debug.Print iconArr(i) & ": left=" & curX & ", gap=" & (curX - prevX) & ", width=" & shp.Width
|
|
End If
|
|
prevX = curX + shp.Width
|
|
curX = curX + shp.Width + gapPt
|
|
Next i
|
|
Application.ScreenUpdating = True
|
|
End Sub
|
|
|
|
' ================= 你的专属调用入口 =================
|
|
Sub RunAlignForMySheet()
|
|
AlignIconsByCenter _
|
|
sheetName:="M1", _
|
|
anchorAddr:="B3", _
|
|
iconArr:=Array("input", "check", "output", "sort", "filter", "fit", "load"), _
|
|
gapPt:=10
|
|
End Sub |