Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default Mouse Pointer

Is there a way to change the mouse pointer as it goes over a cell without
selecting the cell? Similiar to how Quickbooks does it on their reports.
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Mouse Pointer

Hi,

There is no mouse over event in Excel but you can do it with this code in a
standard module. To activate it run the sub 'Hook mouse'. To deactivate it
run the sub
'unhook mouse'. Change the range in the hook mouse sub to whatever you want.

I can't remember where I copied this code from and the source isn't credited
in the comments so apologies and thanks to the original author.

Option Explicit

Declare Function SetWindowsHookEx Lib _
"user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As
Long, _
ByVal hmod As Long, ByVal dwThreadId As Long) As Long

Declare Function CallNextHookEx Lib "user32" _
(ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As
Any) As Long

Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As
Long

Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Type POINTAPI
x As Long
Y As Long
End Type

Const HC_ACTION = 0
Const WH_MOUSE_LL = 14
Const WM_MOUSEMOVE = &H200

Dim hhkLowLevelMouse As Long
Dim blnHookEnabled As Boolean
Dim udtCursorPos As POINTAPI
Dim objCell As Variant
Dim objTargetRange As Range


Public Function LowLevelMouseProc _
(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

'\\ Prevent error if objCell is Nothing
On Error Resume Next

If (nCode = HC_ACTION) Then

'\\ when Mouse is moved
If wParam = WM_MOUSEMOVE Then

'\\ Process WM_MOUSEMOVE message first
LowLevelMouseProc = False

'\\ Get Mouse Pointer location in Screen Pixels
GetCursorPos udtCursorPos

'\\ Get Cell under Cursor
Set objCell = ActiveWindow.RangeFromPoint(udtCursorPos.x,
udtCursorPos.Y)

'\\ If Cursor not over a Range or outside TargetRange restore
Default Cursor
If objCell Is Nothing Or _
(Union(objCell, objTargetRange).Address <
objTargetRange.Address) Then
Application.Cursor = xlDefault
Else
Application.Cursor = xlIBeam
End If
End If
Exit Function
End If

' \\ Call next hook if any
LowLevelMouseProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)

End Function


Sub Hook_Mouse()

'\\ Prevent Hooking more than once
If blnHookEnabled = False Then
'\\ Change this Target range address as required
Set objTargetRange = Sheets("Sheet1").Range("A1:A20")

hhkLowLevelMouse = SetWindowsHookEx _
(WH_MOUSE_LL, AddressOf LowLevelMouseProc, Application.Hinstance, 0)
blnHookEnabled = True

End If

End Sub


Sub UnHook_Mouse()

If hhkLowLevelMouse < 0 Then UnhookWindowsHookEx hhkLowLevelMouse
'\\ reset Flag
blnHookEnabled = False

End Sub


"ranswrt" wrote:

Is there a way to change the mouse pointer as it goes over a cell without
selecting the cell? Similiar to how Quickbooks does it on their reports.
Thanks

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
mouse pointer Atishoo Excel Discussion (Misc queries) 2 June 16th 08 04:25 PM
mouse pointer robnsd Excel Discussion (Misc queries) 2 April 20th 07 10:17 PM
mouse pointer . . . again! lightbulb_bill[_2_] Excel Programming 1 August 15th 05 11:48 PM
Mouse pointer Simon Lloyd[_473_] Excel Programming 5 June 8th 04 07:08 PM
mouse pointer jim c. Excel Programming 0 September 6th 03 11:25 PM


All times are GMT +1. The time now is 12:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"