Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Custom Mouse over Cell Event Help

You probably want a Java Script newsgroup.

"None" wrote:

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.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Custom Mouse over Cell Event Help

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" wrote in message
...
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Custom Mouse over Cell Event Help

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" wrote in message
...
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"
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" wrote in message
.. .
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.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Custom Mouse over Cell Event Help

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" wrote in message
...
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" wrote in message
...
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"
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" wrote in message
.. .
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.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Custom Mouse over Cell Event Help

And you can't use comments,... why?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"None" wrote in message
...
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.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Custom Mouse over Cell Event Help

See, that's why I asked. APIs can be such a bother.

Personally, I'd let the user scroll. But a simpler solution might be to use
a timer to start code that looks for comments, and if a comment is visible,
make sure it is completely on screen.

Even easier would be to place a picture control from the controls toolbox
over the cell in question. Make the picture control invisible, then double
click on it in design mode, which brings you to the worksheet code module,
with the frame of the Image1_Click event procedure. Delete this one, but
select Image1 from the left dropdown of the code module, and MouseMove from
the right dropdown, then put the comment moving code in this procedure.

Make the procedure in the worksheet code module look like this:

Private Sub Image1_MouseMove(ByVal Button As Integer, ByVal Shift As
Integer, _
ByVal X As Single, ByVal Y As Single)
With Image1.TopLeftCell.Comment
.Visible = True
With .Shape
.Top = 100
.Left = 100
End With
Application.OnTime Now + TimeValue("0:00:10"), _
"'HideComment """ & Image1.TopLeftCell.Address & """'"
End With
End Sub

and put this procedure into a regular code module:

Sub HideComment(sAddress As String)
ActiveSheet.Range(sAddress).Comment.Visible = False
End Sub

The reason for this is that making the comment visible does not allow for
hiding it when you mouse away from the image control. This code hides it
after ten seconds.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"None" wrote in message
...

Glad you asked, maybe you know a fix for the issue I have with
comments. If I have a commnet on a cell that is close to the edge of
the viewable worksheet, it appears off the scrren. I know the user
can just use the horizonal scroll bar to move over, but this seems
"unclean" to me. I would have thought the programers of excel would
have at least allowed you to control where the comment would have
poped up.


And you can't use comments,... why?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"None" wrote in message
. ..
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.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Custom Mouse over Cell Event Help

JLGWhiz schrieb:
You probably want a Java Script newsgroup.

"None" wrote:


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.



On my website, you'll find a com-addin named xlEventServer (description
is only in german; tested with german-excel, WinXP Home/Pro and
Win2000). It triggers some new events, like OnMove, OnButtonDown,
OnMouseWheel. But use on your own risk :-)

Install the addin, and add the following code to a normal code-module.

Option Explicit

Private BlockOnMove As Boolean
Public EnableWheelEvent As Boolean

Private Const DELTA_MOUSEWHEEL = 3&
Private Const DELTA_ZOOM = 5&

' Enables OnMouseWheel-Event ...
Public Function GetWheelState() As Boolean
'GetWheelState = EnableWheelEvent
GetWheelState = False
End Function

' OnMove-Event
Public Sub OnMove(Target As Excel.Range, x As Long, y As Long)

On Error Resume Next

If Not BlockOnMove And Selection.Count = 1 Then
Static oldRange As Excel.Range
oldRange.Interior.ColorIndex = oldRange.Interior.ColorIndex Xor 4
If Target.Interior.ColorIndex < 0 Then
Target.Interior.ColorIndex = 4
Else
Target.Interior.ColorIndex = Target.Interior.ColorIndex Xor 4
End If
Set oldRange = Target
End If

End Sub

--
Gruß
Thomas

http://rtsoftwaredevelopment.de
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Custom Mouse over Cell Event Help

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.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Custom Mouse over Cell Event Help

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"
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" wrote in message
.. .
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.


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Custom Mouse over Cell Event Help


?

LOL I am writing a budgeting/Debt reduction program in excel with VBA.
How will java help me?


On Sun, 10 Dec 2006 12:25:01 -0800, JLGWhiz
wrote:

You probably want a Java Script newsgroup.

"None" wrote:

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.




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Custom Mouse over Cell Event Help

I will chack it out. Thanks!

On Mon, 11 Dec 2006 16:10:36 +0800, "NickHK"
wrote:

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" wrote in message
...
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" wrote in message
...
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"
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" wrote in message
.. .
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.





  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Custom Mouse over Cell Event Help


Glad you asked, maybe you know a fix for the issue I have with
comments. If I have a commnet on a cell that is close to the edge of
the viewable worksheet, it appears off the scrren. I know the user
can just use the horizonal scroll bar to move over, but this seems
"unclean" to me. I would have thought the programers of excel would
have at least allowed you to control where the comment would have
poped up.


And you can't use comments,... why?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"None" wrote in message
.. .
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.


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 Up or Down Event billinr Excel Discussion (Misc queries) 2 July 5th 07 07:46 PM
mouse over event rk0909 Excel Discussion (Misc queries) 1 September 3rd 06 02:51 PM
mouse click event? Ramthebuffs[_29_] Excel Programming 2 March 8th 06 04:29 AM
capture right mouse button click event on cell Reinhard Thomann Excel Programming 0 January 20th 05 11:41 AM
Mouse Down event Pal Excel Programming 2 January 24th 04 12:25 PM


All times are GMT +1. The time now is 01:36 AM.

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"