This document contains VBA code for Excel worksheet event macros. It includes macros that will add or delete a command bar button depending on the value in cell A1, and a macro to load a userform when the button is clicked. The button will be added on worksheet activation and removed on deactivation.
This document contains VBA code for Excel worksheet event macros. It includes macros that will add or delete a command bar button depending on the value in cell A1, and a macro to load a userform when the button is clicked. The button will be added on worksheet activation and removed on deactivation.
This document contains VBA code for Excel worksheet event macros. It includes macros that will add or delete a command bar button depending on the value in cell A1, and a macro to load a userform when the button is clicked. The button will be added on worksheet activation and removed on deactivation.
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
' If [A1].Value = "1 번" Then ' Cancel = True ' Else ' Cancel = False ' End If End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim a As CommandBar If Not Intersect(Target, [A1]) Is Nothing Then On Error Resume Next If [A1].Value = "1 번" Then Call Add_CommandBar Else Call Del_CommandBar End If End If On Error GoTo 0 End Sub
Private Sub Worksheet_Deactivate()
Call Del_CommandBar End Sub
Private Sub Worksheet_Activate()
Call Add_CommandBar End Sub Sub Add_CommandBar() Dim a As CommandBar On Error Resume Next If [A1].Value = "1 번" Then Set a = Application.CommandBars("Cell") With a.Controls.Add(Type:=msoControlButton, Before:=1) .Caption = "위치 입력" '명령 이름 .FaceId = 136 '아이콘 .OnAction = "Load_Userform1" '유저폼 부르기 .Tag = "Test" End With End If End Sub
Sub Del_CommandBar() On Error Resume Next Application.CommandBars("Cell").Reset End Sub