Looking for the code to center worksheet based on monitor size

lnagel

Board Regular
Joined
May 28, 2018
Messages
117
anyone already have the worksheet centering code that works no matter what the monitor size - that would be willing to share?

Also want to lock current worksheet size (make current size the full screen size). Thanks in advance
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
anyone already have the worksheet centering code that works no matter what the monitor size - that would be willing to share?

Code:
Sub Window_Mid()
Dim shW#, maxW#
Application.ScreenUpdating = False
With ActiveWindow
    .WindowState = xlMaximized
    maxW = Application.Width
    .WindowState = xlNormal
    shW = Application.Width
    .Top = 20
    .Left = (maxW - shW) / 2
End With
End Sub
 
Upvote 0
I want to make the current worksheet size the "Fullscreen" Size. So Not sure if I am looking for code to eliminate the fullscreen click (top right corner) or just to change the "fullscreen" option to set the worksheet size to a specific width and height.
 
Upvote 0
Upvote 0
Maybe this will make more sense as I have figured out definite specifics

I have resized a Worksheet to be viewed at exactly 1452 Points in Width and 792 Points in Height

If the user changes that size (fullscreen click or manual resize) and then saves & closes the workbook - I want to reset the size of the Worksheet to 1452W X 792H the next time it is opened (so would be a sub called in "This WorkBook Code")

Additionally - I would also like to have the Left Right Scroll bar reset to full Left and the Up Down Scroll bar reset to Full Up upon opening

Thanks
 
Upvote 0
Figured out the scrollbars part - In Case Anyone else is interested here is

the Left/Right Center the Activewindow (regardless of Monitor Size) and 20 points (I think) down from the top edge of Monitor Screen
and then move the Left/Right Scroll Bar all the way to the left and the Up/Down Scroll Bar all the way up

Still looking for the code to set the Worksheet Size to Exactly 1452 X 792

Code:
Sub Window_Mid()
Dim shW#, maxW#
Application.ScreenUpdating = False
With ActiveWindow
    .WindowState = xlMaximized
    maxW = Application.Width
    .WindowState = xlNormal
    shW = Application.Width
    .Top = 20
    .Left = (maxW - shW) / 2
    ActiveWindow.ScrollRow = 1
    ActiveWindow.ScrollColumn = 1
End With
End Sub
 
Last edited:
Upvote 0
Still looking for the code to set the Worksheet Size to Exactly 1452 X 792
Code readily available here : https://www.google.com.hk/search?q=....69i57j0l5.30365j1j8&sourceid=chrome&ie=UTF-8
Code:
Sub Window_Mid()
Dim shW#, maxW#
With Application
    .ScreenUpdating = False
    With .ActiveWindow
[COLOR=#ff0000]        .Width = 1450[/COLOR]
[COLOR=#ff0000]        .Height = 792[/COLOR]
        .WindowState = xlMaximized
        maxW = .Width
        .WindowState = xlNormal
        shW = .Width
        .Top = 20
        .Left = (maxW - shW) / 2
        .ScrollRow = 1
        .ScrollColumn = 1
    End With
    .ScreenUpdating = False
End With
End Sub
 
Upvote 0
If you want to centre vertically, instead of 20 from the top :
Code:
Sub Window_Mid()
Dim maxW#, maxH#
With Application
    .ScreenUpdating = False
    With .ActiveWindow
        .Width = 1450
        .Height = 792
        .WindowState = xlMaximized
        maxW = .Width
        maxH = .Height
        .WindowState = xlNormal
        .Top = (maxH - .Height) / 2
        .Left = (maxW - .Width) / 2
        .ScrollRow = 1
        .ScrollColumn = 1
    End With
    .ScreenUpdating = False
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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