Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Prevent Extreme Zoom Out. Mouse Wheel Event?

I posted this question a couple of days ago. I didnt get a response, and
wanted to put this question back at the 'top of the list'. Basically, I am
trying to come up with a way of preventing a user from zooming out too far.
Is there a way to limit the user to say 30% of zoom. I have this:


If ActiveWindow.Zoom <= 30 Then
ActiveWindow.Zoom = 40
MsgBox("Already Zoomed Out as Far as Possible", _
vbOKCancel, "Max. Zoom")
End If

Somehow, the event has to be fired by a mouse wheel event (I believe thats
what it is called). Ive done quite a bit of research on this and all I can
come up with is some ways of doing this in Access, but not in Excel. Does
anyone know of a way to control the mouse wheel event in Excel?

Thanks,
Ryan---


--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Prevent Extreme Zoom Out. Mouse Wheel Event?

I found this info on another site - hth

http://www.andreavb.com/tip060008.html

dmoney

"ryguy7272" wrote:

I posted this question a couple of days ago. I didnt get a response, and
wanted to put this question back at the 'top of the list'. Basically, I am
trying to come up with a way of preventing a user from zooming out too far.
Is there a way to limit the user to say 30% of zoom. I have this:


If ActiveWindow.Zoom <= 30 Then
ActiveWindow.Zoom = 40
MsgBox("Already Zoomed Out as Far as Possible", _
vbOKCancel, "Max. Zoom")
End If

Somehow, the event has to be fired by a mouse wheel event (I believe thats
what it is called). Ive done quite a bit of research on this and all I can
come up with is some ways of doing this in Access, but not in Excel. Does
anyone know of a way to control the mouse wheel event in Excel?

Thanks,
Ryan---


--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Prevent Extreme Zoom Out. Mouse Wheel Event?

Thanks dmoney; looks like a good resource, but seems to be much more focused
on VB than VBA for Excel. I modified the code slightly, and am now working
with this:

Option Explicit

'API
Private Declare Function CallWindowProc Lib "user32.dll" Alias
"CallWindowProcA" ( _
ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias
"SetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

'Constants
Public Const MK_CONTROL = &H8
Public Const MK_LBUTTON = &H1
Public Const MK_RBUTTON = &H2
Public Const MK_MBUTTON = &H10
Public Const MK_SHIFT = &H4
Private Const GWL_WNDPROC = -4
Private Const WM_MOUSEWHEEL = &H20A

'Variables
Private hControl As Long
Private lPrevWndProc As Long

Private Function WindowProc(ByVal lWnd As Long, ByVal lMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

If lMsg = WM_MOUSEWHEEL Then
Screen.ActiveSheet.MouseWheelRolled
End If

If lMsg < WM_MOUSEWHEEL Then
WindowProc = CallWindowProc(lPrevWndProc, lWnd, lMsg, wParam, lParam)
End If
End Function

Public Sub Hook(ByVal hControl_ As Long)
hControl = hControl_
lPrevWndProc = SetWindowLong(hControl, GWL_WNDPROC, AddrOf("WindowProc"))
End Sub

Public Sub UnHook()
Call SetWindowLong(hControl, GWL_WNDPROC, lPrevWndProc)
End Sub

Public Sub MouseWheelRolled()
Call Worksheet_Change
End Sub

In Sheet1 Module I have this:
Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveWindow.Zoom <= 30 Then
ActiveWindow.Zoom = 40
MsgBox "Already Zoomed Out as Far as Possible", _
vbOKCancel, "Max. Zoom"
End If
End Sub


The macro does not fire when I hold the Ctrl key and move the mouse wheel to
zoom out. What am I doing wrong?

Thanks,
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"dmoney" wrote:

I found this info on another site - hth

http://www.andreavb.com/tip060008.html

dmoney

"ryguy7272" wrote:

I posted this question a couple of days ago. I didnt get a response, and
wanted to put this question back at the 'top of the list'. Basically, I am
trying to come up with a way of preventing a user from zooming out too far.
Is there a way to limit the user to say 30% of zoom. I have this:


If ActiveWindow.Zoom <= 30 Then
ActiveWindow.Zoom = 40
MsgBox("Already Zoomed Out as Far as Possible", _
vbOKCancel, "Max. Zoom")
End If

Somehow, the event has to be fired by a mouse wheel event (I believe thats
what it is called). Ive done quite a bit of research on this and all I can
come up with is some ways of doing this in Access, but not in Excel. Does
anyone know of a way to control the mouse wheel event in Excel?

Thanks,
Ryan---


--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Zoom with Scroll wheel Noonie12 Excel Discussion (Misc queries) 4 April 30th 09 10:13 PM
Fix for mouse wheel in VBE XP Excel Programming 7 May 18th 06 07:02 PM
PS/2 wheel mouse in VBA George Excel Discussion (Misc queries) 1 November 3rd 05 04:44 PM
Mouse Wheel & Mouse Drivers Otto Moehrbach Excel Programming 3 May 7th 05 09:16 PM
my mouse wheel works the zoom jsmonje Excel Discussion (Misc queries) 3 December 2nd 04 12:41 PM


All times are GMT +1. The time now is 03:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"