Adjust Zoom after Resizing the Window

AAAAndy

New Member
Joined
Feb 1, 2010
Messages
27
Hi! I'm new to MrExcel.com - it's highly recommended by an associate.
Here’s the question:
I've created a summary report with VBA code that resizes the sheet to fit the size of the window - just like using Zoom to Selection. The code runs whenever that worksheet is selected.
If the Excel window is small, the range automatically zooms to fit the window when the sheet is selected.
But if you then resize the window, the range does not zoom out to fit the window. (Unless you click on another page, then click back to the Summary Page.)
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Is there a VB/VBA function that recognizes – as an EVENT – when the window is resized? Then that would trigger the code to zoom to the correct size.
<o:p> </o:p>
If not, then I’ll add a button to the screen that will resize the range.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Is there a VB/VBA function that recognizes – as an EVENT – when the window is resized?
Yes there is, curiously enough called "Workbook_WindowResize" with the event code syntax

Code:
Private Sub Workbook_WindowResize(ByVal Wn As Window)
 
'your code goes here
 
End Sub


It goes into the workbook module.
 
Upvote 0
Private Sub Workbook_WindowResize(ByVal Wn As Window)

What's up with that? I did not know that existed or I at least forgot that it did. :)

Unfortunately, this event does not seem to fire when the application window is rezised. Mr. Urtis! What's the option when the app window is rezised? Is there one?

Code:
Private Sub Workbook_WindowResize(ByVal Wn As Window)
    If TypeOf ActiveSheet Is Worksheet Then
        If Range("ZoomRange").Parent.Name = ActiveSheet.Name Then
            
            Dim SaveSelection As Range
            
            Application.ScreenUpdating = False
            If Not Intersect(Selection, Range("ZoomRange")) Is Nothing Then
                Set SaveSelection = Selection
            Else
                Set SaveSelection = Cells(1)
            End If
            Application.Goto Range("ZoomRange").Cells(1), True
            Range("ZoomRange").Select
            ActiveWindow.Zoom = True
            SaveSelection.Select
            Application.ScreenUpdating = True
           
        End If
    End If
End Sub
 
Last edited by a moderator:
Upvote 0
Upvote 0
"I do not have 100% faith in their relaibility and stability so I stay away from them."

Oh... Subclassing. I agree with you. Probably not worth it but don't tell Jaafar that. By the time he is done with Excel, it will be doing his laundry and washing his dishes. :)
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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