我目前遇到表格按钮与行不对齐的问题。我运行以下代码,每次都得到不同的结果。根据下面的快照,看起来除非我缩放到100%视图,否则会发生以下错位。有没有人有解决方案?
主要程序:
Private Sub Workbook_Open()
' Sub ColumnA_Buttons()
Dim buttons As Button
Dim rng As Range
Dim LineQty As Variant
Application.ScreenUpdating = False
ActiveSheet.buttons.Delete
LineQty = 20
For i = 1 To LineQty
Set rng = ActiveSheet.Range(Cells(i, 1), Cells(i, 1))
Set buttons = ActiveSheet.buttons.Add(rng.Left, rng.Top, rng.Width, rng.Height)
With buttons
.OnAction = "Buttons"
.Caption = "Line " & i
.Name = "Line " & i
End With
Next i
Application.ScreenUpdating = True
End Sub
按钮模块:
Sub buttons()
Dim Btn As Variant
Btn = Application.Caller
'MyUserForm1.Show 'Launch custom userform
MsgBox Btn & " was Clicked"
End Sub