gpt4 book ai didi

vba - 在 Excel VBA 中手动设置 Application.Caller

转载 作者:行者123 更新时间:2023-12-04 21:35:46 36 4
gpt4 key购买 nike

我一直在尝试使用 button1 来激活 button2。问题是 button2 必须使用 application.caller ,它默认为最初按下的按钮(button1)。

如何为 application.caller 设置新值?

这是示例代码:

按钮1:

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

按钮 2:
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

...或将按钮本身作为参数传递

关于vba - 在 Excel VBA 中手动设置 Application.Caller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38515664/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com