在Excel中使用WScript.CreateObject

我一直在研究使用WScript.CreateObject(“WScript.Shell”)来为用户窗体上的命令button创build多行,hover,5秒popup窗口。 从一切我可以认为这应该工作正常,但是给出了一个“variables没有定义”的错误。 在debugging时,它突出显示SET行中的“WScript”作为问题。 请帮我迷路。

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 

结束小组

你将需要添加一个引用到WScript来使用它的CreateObject – 但你不需要; 而是使用VBA的CreateObject来创build一个.Shell的实例:

 Set WshShell = CreateObject("WScript.Shell") BTN = WshShell.PopUp("What do you want to do?", 5) 

然后使用MsgBox而不是WScript.Echo

 ... MsgBox "Do it now."