Nelly,
Excel does not natively expose info about the mouse movement/position.
You can fake something with some API call (GetCursorPos etc) and a timer...
Using the Timer from
http://vb.mvps.org/samples/project.asp?id=TimerObj
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As
Long
Dim CursorPt As POINTAPI
Private WithEvents MyTimer As CTimer
Const CheckRange As String = "M8:R21"
Private Const HIGHZOOM As Long = 200
Private Const LOWZOOM As Long = 100
Private Sub Worksheet_Activate()
If MyTimer Is Nothing Then Set MyTimer = New CTimer
With MyTimer
.Interval = 500
.Enabled = True
End With
End Sub
Private Sub Worksheet_Deactivate()
If Not MyTimer Is Nothing Then
With MyTimer
.Enabled = False
End With
End If
End Sub
Private Sub MyTimer_Timer()
Dim RetVal As Long
Dim CursorRange As Range
With ActiveWindow
RetVal = GetCursorPos(CursorPt)
On Error Resume Next
Set CursorRange = .RangeFromPoint(CursorPt.x, CursorPt.y)
On Error GoTo 0
If Not CursorRange Is Nothing Then
If Application.Intersect(Range(CheckRange), CursorRange) Is Nothing
Then
.Zoom = LOWZOOM
Else
.Zoom = HIGHZOOM
End If
Else
.Zoom = LOWZOOM
End If
End With
End Sub
However, changing the zoom, affects the range the mouse is over, so you can
get a rather sickening effect where the zoom jumps in and out.
You can maybe play with setting the cursor position or slowing the
timer..but you get the idea.
-------------- An easier method
If this is only for viewing, as the user cannot click on the cells
underneath, use 2 Image controls, large one under a smaller one. Whilst this
works, I not sure the effect is suitable:
Private Const HIGHZOOM As Long = 200
Private Const LOWZOOM As Long = 100
Private Sub ImageSmall_MouseMove(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
If ActiveWindow.Zoom <> HIGHZOOM Then
ActiveWindow.Zoom = HIGHZOOM
With Image2
Application.Goto .TopLeftCell, True
End With
End If
End Sub
Private Sub ImageLarge_MouseMove(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
If ActiveWindow.Zoom <> LOWZOOM Then
ActiveWindow.Zoom = LOWZOOM
End If
End Sub
-------------- Probably the easiest method
Alternatively, you could create a linked picture of the range in question
and expand that picture:
- Select the required range. Copy.
- Hold down SHIFT and click Edit>Paste Picture Link.
- Size and position as required.
NickHK