vba 在 Excel 中使用 WScript.CreateObject
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43806988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using WScript.CreateObject in Excel
提问by Hareborn
I have been researching using
我一直在研究使用
WScript.CreateObject("WScript.Shell")
to act as a means to create a multi-line, hover-over, 5-second pop-up for a command button on a Userform. From everything I can figure this should be working fine, but it's giving a "Variable not defined"error. On debugging it highlights "WScript"
in the Set
line as the issue.
作为一种为用户窗体上的命令按钮创建多行、悬停、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
回答by Alex K.
You would need to add a reference to WScript
to use its CreateObject
- but you don't need to; instead use VBA's CreateObject
to create an instance of .Shell
:
您需要添加WScript
对使用它的引用CreateObject
- 但您不需要;而是使用 VBACreateObject
创建一个实例.Shell
:
Set WshShell = CreateObject("WScript.Shell")
BTN = WshShell.PopUp("What do you want to do?", 5)
And subsequently use MsgBox
instead of WScript.Echo
:
随后使用MsgBox
代替WScript.Echo
:
...
MsgBox "Do it now."