While mouse cursor on top of A1 cell

Erdinç E. Karaçam

Board Regular
Joined
Sep 23, 2006
Messages
202
Hi everyone,

I would like to change A1 cell's Interior.ColorIndex to red color and A1's font format to Italic, while mouse cursor on top of A1 cell.

Can i do it with a VBA code or any different way to do it?

Thanks a lot.


:biggrin: For a funny example:

Code:
Sub CursorOnA1() 
    If MouseCursor OnTopOf [A1] Then 
        With [A1] 
            .Interior.ColorIndex = 3 
            .Font.Italic = True 
        End If 
    End If 
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Doesn't work for me, the line:

If MouseCursor OnTopOf [A1] Then

Comes up red in Visual Basic Editor
 
Upvote 0
Hi Norie. The answer from DRJ with Guru status says you can't do it. I disagree. You can do it, but, depending on rather the OP needs to directly edit in the cell, will lend to differing levels of complexity. So is this an official crosspost if the answer from another board's "Guru" is "no"? :)
 
Upvote 0
Tom

Not sure how you would define an 'official' cross-post, just thought I'd give you a heads-up.:)

When I saw the original post over at the other forum I also thought it would be possible, but realised it would probably involve using the Windows API and/or other complicated code.

The OP seemed fine with the response that it wasn't possible, so I was suprised to see the question posted here.

If you think it's possible then it probably is.:)
 
Upvote 0
Hi everyone :biggrin:

I asked this question an another Forum and Guru said me that is not possible for a worksheet.

I think this answer should be true. But i am still thinking of API's benefits and i am saying myself hey Erdinç! maybe you can find a way to do it by an API.

But finally i don't know what going to be end of my this wonder.

Anyway, Thank you you very much you all.

Best regards. :rolleyes:
 
Upvote 0
sorry, having problems posting ..... 3rd attempt

call Starttimer and Stoptimer when required ....

Rich (BB code):
Option Explicit
'//
'// Cursor pos orig by rafaaj2000

'// Addressof routines found here;
'// http://www.xcelfiles.com/API_09.html
'// http://www.xcelfiles.com/VBA_Clock.html

'// Timer routines;
'// http://www.xcelfiles.com/API_02.html
'//


Declare Function SetTimer _
    Lib "user32" ( _
        ByVal hWnd As Long, _
        ByVal nIDEvent As Long, _
        ByVal uElapse As Long, _
        ByVal lpTimerFunc As Long) _
As Long

Declare Function KillTimer _
    Lib "user32" ( _
        ByVal hWnd As Long, _
        ByVal nIDEvent As Long) _
As Long

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

Type POINTAPI
    x As Long
    Y As Long
End Type

Dim m_blnTimerOn As Boolean
Dim m_lngTimerId As Long
Dim m_NewRange As Range
Dim m_OldRange As Range

Sub StartTimer()
If Not m_blnTimerOn Then
    m_lngTimerId = SetTimer(0, 0, 0.05, AddressOf TimerProc)
    m_blnTimerOn = True
End If
End Sub

Public Function TimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Dim lngCurPos As POINTAPI
'
On Error Resume Next
GetCursorPos lngCurPos

Set m_NewRange = ActiveWindow.RangeFromPoint(lngCurPos.x, lngCurPos.Y)

If m_NewRange.Address <> m_OldRange.Address Then
    With Range("A1")
        .Font.ColorIndex = 0
        .Font.Italic = False
    End With
End If

If m_NewRange.Address = "$A$1" Then
    With Range("A1")
        .Font.ColorIndex = 3
        .Font.Italic = True
    End With
End If
    
'//
Set m_OldRange = m_NewRange
TimerProc = 0

End Function

Sub StopTimer()
If m_blnTimerOn Then
    KillTimer 0, m_lngTimerId
    m_blnTimerOn = False
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top