0

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

1 Answer 1

1

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."
Sign up to request clarification or add additional context in comments.

2 Comments

I tried your suggestion and had a few glitches. It created almost 200 msgbox's in the time it took me to move on and off the command button and the popup never displayed.
That's because you are using the MouseMove event, so it fires every time your mouse moves within the bounds of the control. Same thing would happen with your original code if you hadn't run into the missing reference problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.