2016-07-21 23 views
1

私はbutton1を使用してbutton2を有効にしようとしています。問題は、button2がapplication.callerを使用しなければならず、デフォルトではボタンが元々押されていることです(button1)。Excel VBAでApplication.Callerを手動で設定する

どのようにして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 

End Subのこのような

+0

この値を設定することはできません。button2の主な機能を、呼び出し元に渡すことができるパラメータを持つ別のサブに移動します。ボタン1またはボタン2から呼び出すことができます。既存のコードがここに含まれていれば、サンプルコードを簡単に投稿できます。 –

+0

それを入れなさい。ありがとう! – CodeHead

答えて

4

何か:

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 
ここ

は、サンプルコードです

...ボタン自体をパラメータとして渡します。

関連する問題