How to Change Mouse Cursor

saurabh

Board Regular
Joined
Feb 28, 2003
Messages
69
Hi All,

There is a small problem,
I want to cahnge the mouse cursor in excel through VBA
as i di in VB
like
Screen.Mousepointer = vbHourGlass
How can i do this foe excel in VBA

Thanks in Advance as i know
i will get the answer immediately.

Thanks agin
Saurabh
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Use the Cursor property of the Application object like this:

Application.Cursor = xlWait

Other possible settings are xlNorthwestArrow, xlIBeam and xlDefault (to reset it).
 
Upvote 0
... and an example I found somewhere a while ago

Code:
Sub ChangeMousePointer()
'Illustrates the various mouse pointer shapes. _
Note that because the Cursor property is not automatically reset _
when the macro stops running, you need to reset the mouse pointer _
by setting the Cursor property to the xlNormal value before your macro stops.
    
    ' Display dialog box indicating mouse pointer will change.
    MsgBox "Click OK to display mouse pointer as hourglass."

    ' Display mouse pointer as hourglass.
    Application.Cursor = xlWait

    ' Wait so mouse pointer change will be noticeable.
    Application.Wait Now + TimeValue("0:0:03")
    MsgBox "Click OK to display mouse pointer as arrow."

    ' Display mouse pointer as arrow
    Application.Cursor = xlNorthwestArrow

    ' Wait so mouse pointer change will be noticeable.
    Application.Wait Now + TimeValue("0:0:03")

    MsgBox "Click OK to display mouse pointer as I-beam."

    ' Display mouse pointer as I-beam.
    Application.Cursor = xlIBeam

    ' Wait so mouse pointer change will be noticeable.
    Application.Wait Now + TimeValue("0:0:03")

    MsgBox "Click OK to return mouse pointer to normal."

    ' Return mouse pointer to normal display.
    Application.Cursor = xlNormal

End Sub
 
Upvote 0
Can you change the cursor when over a specific range or cell

Hi

Would you know how you can check if the mouse is over a particular cell so you can chnage the cursor (or range of cells). There is no standard event - is there another way to trap this or the ability to create / define a new event to trap this. It is possible as I have seen this before - the mouse cursor does chnage in Excel anyhow but how to you surface this event


Tahnks in advance
 
Upvote 0
This is an old thread but I have a slightly different approach using a class module instead of just changing the cursor in VBA in each module. Number one advantage of the class approach is its automatic restoration of the cursor in case of a fatal code error.

Code:
'----------------------------------------------------------------------
' DESCRIPTION: Class Module clshourglassXL
'-------------
'This class not only provides the SetCursor method, which provides a 
' convenient method of setting the hourglass cursor, but it automatically
' restores the cursor when the class object is destroyed.
'
'Although you can call the Restore method to restore the cursor, it is not
' necessary.  Using clsHourglassXL guarantees the cursor will be restored
' when the subroutine terminates, even if the subroutine terminates due 
' to an unhandled run-time error!
'----------------------------------------------------------------------
' HISTORY:
'---------
' Adapted from Access VBA
'----------------------------------------------------------------------
' INPUT:
'-------
'    cCursor.setCursor
'     OR
'    cCursor.Restore
'----------------------------------------------------------------------
' OUTPUT:
'--------
' Changes the cursor hourglass
'----------------------------------------------------------------------
' SAMPLE CALL:
'-------------
'Declare your clsHourglassXL object within a subroutine:
'
'Sub Eyeglass()
'    Dim cCursor As New clsHourGlassXL
'    cCursor.SetCursor
'Stop
'    cCursor.Beam
'Stop
'    cCursor.Arrow
'Stop
'     'Perform lengthy tasks here
'     cCursor.Restore
' End Sub
'----------------------------------------------------------------------'DECLARATIONS:
'-------------
Option Explicit
#Const DEBUG_ = False                  ' Set to False for Release version or True for Development
Private Const C_MODULE_NAME = "clsHourGlassXL"
Private mintOldPointer As Integer ' Save Current Pointer State
Private Sub Class_Initialize()
    On Error Resume Next
    '  Save current mouse pointer
    mintOldPointer = Application.Cursor
    '  Change to hourglass
    Application.Cursor = xlWait 'vbHourGlass
End Sub
Private Sub Class_Terminate()
Const C_PROC_NAME = "Class_Terminate"
    Restore
End Sub
Public Sub SetCursor()
Const C_PROC_NAME = "SetCursor"
    ' Set mouse pointer to hourglass/wait state.
    Application.Cursor = xlWait
End Sub
Public Sub Restore()
Const C_PROC_NAME = "Restore"
    ' Return mouse pointer to normal display.
    Application.Cursor = xlDefault
End Sub
Public Sub Beam()
Const C_PROC_NAME = "Beam"
    ' Set mouse pointer to IBeam display.
    Application.Cursor = xlIBeam
End Sub
Public Sub Arrow()
Const C_PROC_NAME = "Arrow"
    ' Set mouse pointer to NorthWestArrow display.
    Application.Cursor = xlNorthwestArrow
End Sub
 
Upvote 0

Forum statistics

Threads
1,218,192
Messages
6,141,009
Members
450,330
Latest member
DylanAndrea231

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top