VBA remembering last window size

Nole321

New Member
Joined
Jun 2, 2021
Messages
11
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hello All,

I have the following code below applied to the workbook, along with more that is not visible but is irrelevant to this question. Two questions to answer. First, is there a way with the following redacted view I have excel to instead of sizing the window by pixes I would like to size the window by a range of cell. Second, when the workbook is deactivated is there a way to have excel remember the last window size to apply to any new workbook that is opened. I would like any new workbook opened to have the last window size and not the current one from this workbook. IDK if either is possible but the latter is more important to me.

VBA Code:
Private Sub Workbook_Open()
ActiveWindow.DisplayHorizontalScrollBar = False
ActiveWindow.DisplayHeadings = False
Application.DisplayStatusBar = False
Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",False)"
With Application
    .WindowState = xlNormal
    .Width = 300
    .Height = 300
End With
End Sub

Private Sub Workbook_Activate()
ActiveWindow.DisplayHorizontalScrollBar = False
ActiveWindow.DisplayHeadings = False
Application.DisplayStatusBar = False
Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",False)"
End Sub

Private Sub Workbook_Deactivate()
ActiveWindow.DisplayHorizontalScrollBar = True
ActiveWindow.DisplayHeadings = True
Application.DisplayStatusBar = True
Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",True)"
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveWindow.DisplayHorizontalScrollBar = True
ActiveWindow.DisplayHeadings = True
Application.DisplayStatusBar = True
Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",True)"
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

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