我一直在研究使用 WScript.CreateObject(" WScript.Shell")来充当创建多行,悬停,5秒钟流行音乐的方法用户表单上的命令按钮的特写。从我能想到的一切来看,这应该可以正常工作,但它会给出"变量未定义" 错误。在调试时,它会在"WScript"
行中突出显示Set
作为问题。
Private Sub CB1604A_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
Dim WshShell
Dim BTN
Set WshShell = WScript.CreateObject("WScript.Shell")
BTN = WshShell.PopUp("What do you want to do?", 5)
Select Case BTN
Case 6
WScript.Echo "Do it now."
Case 7
WScript.Echo "Do it later."
Case -1
WScript.Echo "Cancel all actions?"
End Select
End Sub
答案 0 :(得分:1)
您需要添加对WScript
的引用才能使用其CreateObject
- 但您并不需要;而是使用VBA CreateObject
来创建.Shell
的实例:
Set WshShell = CreateObject("WScript.Shell")
BTN = WshShell.PopUp("What do you want to do?", 5)
然后使用MsgBox
代替WScript.Echo
:
...
MsgBox "Do it now."