Change Mouse Pointer Image in Workbook

R

RyanH

I have a Worksheet Double Click Event in a particular Workbook. Is there a
way to change the mouse image from a "plus sign" to a typical "arrow"? This
would help to me more precise in double clicking cells.
 
T

Tom Hutchins

The following event macros will make the cursor an arrow whenever the
workbook containing them is active:

Private Sub Workbook_Activate()
Application.Cursor = xlNorthwestArrow
End Sub

Private Sub Workbook_Deactivate()
Application.Cursor = xlDefault
End Sub

Copy & paste these into the ThisWorkbook module of your workbook. If you are
new to macros, this link to Jon Peltier's site may be helpful:
http://peltiertech.com/WordPress/2008/03/09/how-to-use-someone-elses-macro/

Hope this helps,

Hutch
 
R

RyanH

It works ok, but two questions.

1.) When I change to the VBE, my cursor doesn't change to the default,
because the workbook I am coding is still active. Is there a way have the
..Cursur = xlNorthwestArrow only when the workbook is the active window? Then
change back to xlDefault when I enter the VBE as the active window.

2.) I wanted to change the cursor to xlNorthwestArrow because I have a
Worksheet Double Click Event. I wanted to improve accuracy of the cursor so
the desired cell could accurately be double clicked. Althought the arrow
cursor does help I still have a small problem. When a user accidentally
double clicks between two cells Excel automatically jumps to the very top or
bottom of the UsedRange in that column. Is there a way to prevent that? I
tried setting Cancel = True in my Worksheet Double Click Event, but it
doesn't seem to work. Any ideas?
 
T

Tom Hutchins

1. I don't have an elegant solution for this, but I have a workaround.
Instead of
using WorkBook events, use WorkSheet events:

Private Sub Worksheet_Activate()
Application.Cursor = xlNorthwestArrow
End Sub

Private Sub Worksheet_Deactivate()
Application.Cursor = xlDefault
End Sub

Copy & paste the code above into the code page for each sheet where the
cursor
should be altered this way. Create a Workbook_Open sub like the following in
the
ThisWorkbook module:

Private Sub Workbook_Open()
Sheets("Sheet1").Activate
End Sub

Change Sheet1 to the name of one of the sheets with the Worksheet_Activate
event
code. This is to ensure that the Worksheet_Activate event gets triggered.

None of this, in itself, fixes the VBE cursor problem. When you are in the
VBE, the active window is still the active worksheet, not the VBE. You will
see this if you run the following sub in the VBE:

Sub AAAAA()
MsgBox ActiveWindow.Caption
End Sub

So, the workaround is to have at least one sheet that does NOT have the
cursor-changing event code. Make that the active sheet before you go to the
VBE. You could put it in a macro like this:

Sub GotoVBE()
ThisWorkbook.Sheets("Sheet4").Activate
Application.SendKeys "%{F11}"
End Sub

There may be a slick way (maybe using API calls) to determine when you are
in the VBE. Perhaps one of the MVPs knows, and can enlighten us both.

2. I don't have a solution for this. Double-clicking a cell border doesn't
trigger any events I can identify - not Worksheet_BeforeDoubleClick, and not
Workbook_SheetBeforeDoubleClick. Tell your users to click in the middle of
the cells.

Hope this helps,

Hutch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top