Hareborn
Hareborn

Reputation: 175

Using WScript.CreateObject in Excel

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.

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

Upvotes: 0

Views: 20432

Answers (1)

Alex K.
Alex K.

Reputation: 175748

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:

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

And subsequently use MsgBox instead of WScript.Echo:

...
MsgBox "Do it now."

Upvotes: 1

Related Questions