Code to control window characteristics

pilot

Active Member
Joined
Feb 17, 2002
Messages
345
Is it possible to add code to a WB or individual Worksheets so that every time a named sheet is viewed, it assumes some predetermined condition(s) such as Normal or Maximized, exact size and location of window in Normal view, etc., regardless of the prevailing conditions when it was last viewed and regardless of the current state of Excel? For example, if two files are open and File1 is currently maximized in the Excel window, when switching to File2 I want to see it in Normal view, not maximized, and with 2 windows (views of the same file) open (which is the way it would last have been viewed/saved). Then, switching to File1, I want it to appear Maximized.

Now for the tough part. Assume File2 is open with 2 windows (views of the same file) side by side which together take up Excel's available screen space. Will code allow you to set window size/location based on the user's screen resolution? Some users have 14" monitors while others have 18" so some are running 800x600 while others are using 1024x768. Ideally, the code would size the two views of the same file proportionately to take up Excel's available screen space, i.e. View1 is 70% of available width and View2 is 30%. Impossible?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Play around with code like the following:

Application.DisplayFullScreen = True
Application.DisplayFullScreen = False
ActiveWindow.View = xlPageBreakPreview
ActiveWindow.View = xlNormalView
Windows.Arrange ArrangeStyle:=xlVertical
Windows.Arrange ArrangeStyle:=xlTiled

There are more options that I haven't listed.

The following code will return your screen resolution:

Option Explicit
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

'Constants for GetSystemMetrics

Const SM_CXSCREEN = 0 ' Width of screen
Const SM_CYSCREEN = 1 ' Height of screen


Sub Get_System_Metrics()

Dim XVal As Long, YVal As Long
YVal = GetSystemMetrics(SM_CYSCREEN)
XVal = GetSystemMetrics(SM_CXSCREEN)
MsgBox "Your Screen Resolution is " & XVal & " by " & YVal

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,220
Members
448,554
Latest member
Gleisner2

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