Re: Custom Mouse over Cell Event Help

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Using Karl's timer class
http://vb.mvps.org/samples/project.asp?id=TimerObj

This seems to work. You need to test more and save often, because if you End
abruptly you will crash Excel.
Make sure you toggle the timer, not just stop your code. Reading Karl's
closely, you can probably fix this.

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, _
ByVal
lpWindowName As String) _
As Long

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA"
(ByVal hWnd1 As Long, _
ByVal hWnd2
As Long, _
ByVal lpsz1
As String, _
ByVal lpsz2
As String) _
As Long

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

Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long,
_
ByVal yPoint
As Long) _
As Long


Private Type POINTAPI
X As Long
Y As Long
End Type


Private WS_Hwnd As Long
Private CursorPos As POINTAPI
Private CursorCell As Range

Dim WithEvents Timer1 As cTimer

Private Sub CommandButton1_Click()
Dim RetVal As Long

If Timer1 Is Nothing Then
Set Timer1 = New cTimer
Timer1.Interval = 250

'XL2002+ has Application.hWnd, but FindWindow etc will work on all,
assuming the class names have remained the same
'Check other versions; this works for 2002

'Get the HWnd of WS in question
RetVal = FindWindowEx( _
FindWindowEx( _
FindWindow("XLMAIN", Application.Caption) _
, 0, "XLDESK", vbNullString) _
, 0, "EXCEL7", ActiveWindow.Caption)

If RetVal = 0 Then
MsgBox "Cannot get Window handle."
Exit Sub
End If

WS_Hwnd = RetVal

End If

'Toggle the timer
With Timer1
.Enabled = Not .Enabled
End With

End Sub

Private Sub Timer1_Timer()
Dim RetVal As Long

RetVal = GetCursorPos(CursorPos)

If RetVal = 0 Then
MsgBox "Cannot get cursor position."
Exit Sub
End If

RetVal = WindowFromPoint(CursorPos.X, CursorPos.Y)

'See if we are in the required window
If RetVal = WS_Hwnd Then
'See if we are on the required WS
If ActiveSheet.Name <> Me.Name Then
Exit Sub
End If
Else
Exit Sub
End If

On Error Resume Next
Set CursorCell = Application.Windows(1).RangeFromPoint(CursorPos.X,
CursorPos.Y)

Debug.Print CursorPos.X, CursorPos.Y;

If Err.Number = 0 Then
Debug.Print CursorCell.Address
Else
Debug.Print "Err"
End If

End Sub

NickHK

"NickHK" <TungCheWah@xxxxxxxxxxx> wrote in message
news:OTc5$5OHHHA.4688@xxxxxxxxxxxxxxxxxxxxxxx
Yes Excel knows where the mouse is, but it is not exposed natively.
You could may use the GetCursorPos API to get the cursor position
(checking
if you actually in Excel at that time with WindowFromPoint), translate to
Excel coordinates and use RangeFromPoint to see if you are over the
required
range. As there's no _MouseMove event on the WS, use a timer.
Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos"
(lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As
Long,
ByVal yPoint As Long) As Long

But it would certainly be easier to just let Excel show the comments by
itself.

NickHK

"None" <erobins@xxxxxxxxxxx> wrote in message
news:2fn3q2tkajqk3lejt876nv2stm19301c84@xxxxxxxxxx
LOL I am writing a budgeting/Debt reduction program in excel with VBA.
I changed the time and date to test some code and forgot to chance it
back. Thanks for letting me know.

The Selction change event will not help, unless they select the cells.
This will not be allowed, as the cells I want to have comments for are
the column headers. The will be locked and unselectable.

Somehow excel must track where the mouse is, as it knows when to
display the in cell comments.

On Mon, 11 Dec 2006 13:06:11 +0800, "NickHK" <TungCheWah@xxxxxxxxxxx>
wrote:

You should fix your system clock as you are currently posting next
year.

But there is no mouse or "ShowComment" events on the worksheet.
What about using the _SelectionChange event ?

NickHK

"None" <erobins@xxxxxxxxxxx> wrote in message
news:scj2q2dvtmgbdf582km36cpbnjkbrnkgf2@xxxxxxxxxx
Anyone know of any "Mouse over cell events?" Here is what I want to
do:

I want to create my own custom cell comments. I will have a few cells
merged and refer to them as my Comment Text Cell. I want to be able
to
check if the mouse is moved over certain cells, and then have the
assigned text show up in my Comment Text Cell.






.



Relevant Pages

  • Re: Fun with Userforms!!!!
    ... the userframe to still remain visible even if Excel is minimized ... It's a Userfrom, it's always a Userform. ... Private Sub Workbook_SheetActivate ...
    (microsoft.public.excel.programming)
  • =?Utf-8?Q?RE:_Referenzwerte_einer_Pivot-Ta?= =?Utf-8?Q?belle_in_Excel_von_VB.2003_aus_=C
    ... Private Sub Worksheet_Activate ... Ich bin leider kein Excel Profi und habe auch noch nicht mit Pivot Tabellen ... Library" gesetzt hast und die Deklaration für myXL und myWS vorgenommen hast, ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Passing excel objects to subroutines as parameters
    ... finds a specified cell value on an excel spreadsheet and then ... formats the found cell and inserts text next to the found cell. ... statement the code simply exits the sub routine and proceeds with ... What I go by when automating, I can play with the stuff in the ...
    (microsoft.public.access.modulesdaovba)
  • Re: Passing excel objects to subroutines as parameters
    ... finds a specified cell value on an excel spreadsheet and then formats ... the found cell and inserts text next to the found cell. ... The sub is ... Set rng = Ws.Range'.Address ...
    (microsoft.public.access.modulesdaovba)
  • Re: SendKeys "(^ {HOME})"
    ... I've tried the following combos of VBA and Excel 2000 v9.0.2720 Application. ... right Cell being the only Cell in the lower, ... Public Sub SelectLoRtPaneUpLfCell() ... Dim lUpLfPaneMaxColNum As Long ...
    (microsoft.public.excel.programming)