Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Mouse Up or Down Event | Excel Discussion (Misc queries) | |||
mouse over event | Excel Discussion (Misc queries) | |||
mouse click event? | Excel Programming | |||
capture right mouse button click event on cell | Excel Programming | |||
Mouse Down event | Excel Programming |