is this possible?

N

Nelly

Is it possible for a sheet to zoom into 200% when the mouse is moved over a
certain area of the sheet?

EG if the mouse is moved over area C10:E15 then the page zooms in to 200%
then when the mouse is moved back the page zooms back out to 100%

Rgds
Nelly
 
N

NickHK

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
 
N

Nelly

Hi Nick thanks for the quick reply, I get the following error message tho

Compile Error:
User-defined type not defined

This is for: Private WithEvents MyTimer As CTimer

Any Ideas?

Rgds
Nelly
 
N

NickHK

Nelly,
Yes because you have to download and incorporate the Timer class at the link
I provided.
Or make/use another suitable timer class.

NickHK
 
N

Nelly

Oh yes many thanks

NickHK said:
Nelly,
Yes because you have to download and incorporate the Timer class at the
link
I provided.
Or make/use another suitable timer class.

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top