在Excel VBA中手动设置Application.Caller

我一直在尝试使用button1来激活button2。 问题是button2必须使用application.caller,默认button被按下(button1)。

如何为application.caller设置一个新的值?

以下是示例代码:

Button1的:

Sub ShowAttack() 'Change the color of the other buttons to the background color. 'Pressed button to lighter color. ActiveSheet.Shapes("AttackButton").Fill.ForeColor.RGB = 14277081 'Other buttons to darker colors. ActiveSheet.Shapes("DefenseButton").Fill.ForeColor.RGB = 12566463 ActiveSheet.Shapes("SpellButton").Fill.ForeColor.RGB = 12566463 'Toggle Appropriate Cells to unhide Dim button As Shape Set button = ActiveSheet.Shapes("AttackButton") rw = button.TopLeftCell.Row Rows((rw + 4) & ":" & (rw + 74)).EntireRow.Hidden = False 'Hide appropriate cells within shown section Set Application.Caller = ActiveSheet.Buttons("WeaponDetailsButton1").Name Application.Run ActiveSheet.Buttons("WeaponDetailsButton1").OnAction Range("AT51").Select End Sub 

button2:

 Sub HideWeaponDetails() Dim b As Object, cs As Integer, rw As Integer Dim sel01 As Integer, sel02 As Integer Set b = ActiveSheet.Buttons(Application.Caller) With b.TopLeftCell cs = .Column rw = .Row End With sel01 = rw + 4 sel02 = rw + 14 Rows(sel01 & ":" & sel02).Select If Selection.EntireRow.Hidden = False Then Selection.EntireRow.Hidden = True Else Selection.EntireRow.Hidden = False End If Range("A" & rw - 4).Select ActiveSheet.Buttons(Application.Caller).Name = "WeaponDetailsButton" & Selection(1).Value Range("AV47").Value = ActiveSheet.Buttons(Application.Caller).Name Range("A1").ClearOutline 

结束小组

像这样的东西:

 Sub ShowAttack() '...do stufff HideWeaponDetails "WeaponDetailsButton1" End Sub Sub button2_click() 'all this Sub does is call HideWeaponDetails HideWeaponDetails Application.Caller End Sub Sub HideWeaponDetails(TheCaller) 'use TheCaller instead of Application.Caller End Sub 

…或将button本身作为parameter passing