有没有一种简单的方法可以在vba、excel中的用户窗体的文本框中启用右键单击弹出菜单?我只是想粘贴到文本框中,但无法在用户表单中右键单击打开菜单
我的代码给出了“编译错误:参数不可选”并突出显示了 With Controls.Add ... 中的 .Add ...
Private myMenu
Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If (Button = 2) Then myMenu.ShowPopup
End Sub
Private Sub UserForm_Initialize()
With UserForm1
.StartUpPosition = 2
End With
Set myMenu = Application.CommandBars.Add(Position:=msoBarPopup, Temporary:=True)
With myMenu
With Controls.Add
.Caption = "Hello"
.OnAction = "HelloWorld"
End With
End With
End Sub
最佳答案
更改此行:
With Controls.Add
致:
With .Controls.Add
关于excel - VBA:在用户窗体中右键单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68806680/