Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
' 檢查是否是空白儲存格
Set CurCell = Target
If Target.Value = "" Then
UserForm1.Show
Cancel = True ' 取消默認的雙擊編輯動作
End If
Set CurCell = Nothing
End Sub
Private Sub FastFood_Button1_Click()
CurCell.Value = FastFood_Button1.Caption
UserForm1.Hide ' 隱藏 UserForm
End Sub
Private Sub FastFood_Button2_Click()
CurCell.Value = FastFood_Button2.Caption
UserForm1.Hide ' 隱藏 UserForm
End Sub
Private Sub Fruit_Button1_Click()
CurCell.Value = Fruit_Button1.Caption
UserForm1.Hide ' 隱藏 UserForm
End Sub
Private Sub Fruit_Button2_Click()
CurCell.Value = Fruit_Button2.Caption
UserForm1.Hide ' 隱藏 UserForm
End Sub
Public CurCell As Range
當 同類型按鈕 數量較多時,會有以下兩點,
下一篇 [VBA] 從視窗按鈕輸入文字 (方法2),將使用「物件類別模組」來改善 (方法1) 的缺點,敬請期待 ~
以上就是這次的分享,請持續關注我 和 Meiko微課頻道,謝謝大家 ~
有任何問題,請在下方留言討論,或加入 LINE社群 Meiko微課小綠群(粉絲交流群),歡迎您的加入。