PC Review


Reply
Thread Tools Rate Thread

Custom Mouse over Cell Event Help

 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      10th Dec 2006
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.
>
>

 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      11th Dec 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 With Quote
 
NickHK
Guest
Posts: n/a
 
      11th Dec 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)>
> 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" <(E-Mail Removed)> wrote in message
> >news:(E-Mail Removed)...
> >> 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 With Quote
 
NickHK
Guest
Posts: n/a
 
      11th Dec 2006
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" <(E-Mail Removed)> wrote in message
news:OTc5$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)>
> > 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" <(E-Mail Removed)> wrote in message
> > >news:(E-Mail Removed)...
> > >> 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 With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      11th Dec 2006
And you can't use comments,... why?

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


"None" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      11th Dec 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed)...
>>> 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 With Quote
 
Thomas Risi
Guest
Posts: n/a
 
      11th Dec 2006
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
 
Reply With Quote
 
None
Guest
Posts: n/a
 
      7th Jan 2007
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 With Quote
 
None
Guest
Posts: n/a
 
      8th Jan 2007
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" <(E-Mail Removed)>
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" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> 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 With Quote
 
None
Guest
Posts: n/a
 
      8th Jan 2007

?

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
<(E-Mail Removed)> 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.
>>
>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the color of cell on mouse over event in calendar control Garg Microsoft VB .NET 0 16th Mar 2007 06:32 AM
how to solve mouse event won't fire again until click on another cell in a datagrid Ryan Liu Microsoft Dot NET 1 13th Feb 2006 02:02 PM
mouse event won't fire again until click on other cell Ryan Liu Microsoft C# .NET 2 11th Feb 2006 05:04 AM
capture right mouse button click event on cell Reinhard Thomann Microsoft Excel Programming 1 20th Jan 2005 12:28 PM
please help with mouse event : custom control and parent form chenedor Microsoft VC .NET 0 30th Sep 2004 05:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:32 AM.