On my user's screen I want to show the (A1:V37) range of cells in Worksheet1
The Width of (A1:V37) is 977 pixels
The Height of (A1:V37) is 642 pixels
If the users monitor size => 977X642 then everything works perfect - Scaling is 100% - (A1:V37) is centered on screen and offsets (Top:Left) are exactly what they need to be
The issue comes in when trying to scale these parameters to fit to a monitor size that is not Wide enough (977) or High enough (642)
Been struggling with this piece of code for a couple of days now - Any assistance would be greatly appreciated
The Width of (A1:V37) is 977 pixels
The Height of (A1:V37) is 642 pixels
If the users monitor size => 977X642 then everything works perfect - Scaling is 100% - (A1:V37) is centered on screen and offsets (Top:Left) are exactly what they need to be
The issue comes in when trying to scale these parameters to fit to a monitor size that is not Wide enough (977) or High enough (642)
Been struggling with this piece of code for a couple of days now - Any assistance would be greatly appreciated
Code:
Sub Window_Mid()
Dim shW#, maxW#, shH#, maxH#
With Application
.WindowState = xlMaximized
maxW = Application.Width 'Returns Monitor Width
maxH = Application.Height 'Returns Monitor Height
.WindowState = xlNormal
If maxW >= 977 And maxH >= 642 Then 'If Screen is larger than 977 x 642 then life is good
Application.Width = 977
shW = Application.Width
Application.Height = 642
shH = Application.Height
Else
' Else set the width of Worksheet 1 to 945 x 431
' This is hard code for testing on my Laptop Screen - I know this fits
' if I can get this part working then I can adapt to other screen width
Application.Width = 945 '
shW = Application.Width
Application.Height = 431
shH = Application.Height
End If
.Width = Application.Width
.Height = Application.Height
.Top = (maxH - shH) / 2
.Left = (maxW - shW) / 2
' Show me the calculation for offset from Top and offset from Left
' Offset works perfect when monitor is larger than desired view
MsgBox "Offset for Top Margin = " & .Top & " : " & maxH & " - " & shH & " / 2" & vbCr & vbCr & _
"Offset for Left Margin = " & .Left & " : " & maxW & " - " & shW & " / 2"
End With
' These are the cells that I want to see in the worksheet - and only these
Sheet1.Range("A1:V37").Select
' My attempt at scaling the worksheet screen size to fit monitor
' Works with large monitor - not with small monitor
ActiveWindow.Zoom = True
ActiveWindow.ScrollRow = 1
ActiveWindow.ScrollColumn = 1
End Sub