Article ID: 147301
Article Last Modified on 10/10/2006
130044 XL: Controlling Appearance of Mouse Pointer Within Macro
'This example requires two dialog sheets.
'Dialog #1: "Maindialog" (without the quotation marks)
'Dialog #2: "WaitDialog" (without the quotation marks)
'On Dialog #1, place a button and assign the procedure, "showWaitDialog,"
'(without quotation marks)to the button.
'Set the DismissButton property for the button.
'On Dialog #2, "WaitDialog," assign the frame to the procedure,
'"WaitDialog," (without the quotation marks).
'Run the procedure "main" from a worksheet.
'The procedure "main" will display a dialog box with a button that is
'assigned to the procedure "showWaitDialog" (without the quotation marks).
'Click the button. This will run the procedure "showWaitDialog." When
"WaitDialog" shows, the procedure assigned to the frame will run. The
'procedure "WaitDialog" will run and show the dialog box "WaitDialog." The
'macro assigned to its frame "showWaitDialog" will run, changing the mouse
'pointer and showing the dialog box "WaitDialog."
'Code starts here:
Option Explicit
'Declaration for APIs.
Private Declare Function loadCursor Lib "USER" _
(ByVal hInstance As Integer, ByVal lpCursorName As Any) _
As Integer
Private Declare Function SetCursor Lib "USER" _
(ByVal hCursor As Integer) As Integer
'Standard Cursor IDs.
Private Const IDC_ARROW = 32512&
Private Const IDC_IBEAM = 32513&
Private Const IDC_WAIT = 32514&
Private Const IDC_CROSS = 32515&
Private Const IDC_UPARROW = 32516&
Private Const IDC_SIZE = 32640&
Private Const IDC_ICON = 32641&
Private Const IDC_SIZENWSE = 32642&
Private Const IDC_SIZENESW = 32643&
Private Const IDC_SIZEWE = 32644&
Private Const IDC_SIZENS = 32645&
Private oldcursor%, fWaitCursorSet As Boolean
'This is the main subroutine.
'This dialog has a button assigned to the procedure "showWaitDialog."
Sub main()
Application.DialogSheets("MainDialog").Show
End Sub
'This procedure should be assigned to the button on the Dialogsheet
'"WaitDialog" (without quotation marks).
Sub showWaitDialog()
Application.DialogSheets("WaitDialog").Show
End Sub
'This sub uses APIs to change the mouse pointer.
Sub SetWait(fSetWaitCursor As Boolean)
'If they have not set the cursor to wait, do not try to un-set it.
If fSetWaitCursor Then
oldcursor% = SetCursor(loadCursor(0, IDC_WAIT))
fWaitCursorSet = True
ElseIf Not fSetWaitCursor And fWaitCursorSet Then
SetCursor oldcursor%
fWaitCursorSet = False
End If
End Sub
'Assign this procedure to the frame of the Dialogsheet "WaitDialog"
'(without the quotation marks).
Sub WaitDialog()
Application.SendKeys ("~")
MsgBox "This does not show"
'This line changes the mouse pointer to an Hour Glass.
SetWait (IDC_WAIT)
'Put your procedure here in place of TestLoop.
TestLoop
SetWait (IDC_ARROW)
Application.DialogSheets("WaitDialog").Hide
End Sub
Sub TestLoop()
Dim x As Integer
For x = 1 To 200
ActiveCell.Value = x
ActiveCell.Offset(1, 0).Select
Next x
End Sub
Additional query words: XL5
Keywords: kbprogramming KB147301