screen size

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi - Please advise if this is possible

If i know the screen size of my monitor - say my monitor is 20 x 11.3 (1920 x 1080 screen res) - is there a way i can have a formula in VBA that will give me the height and and width of the excel window if it was maximised?

The reason why i ask is that i have several of screen sizes a user can open this spreadsheet on - i want to change the zoom level depending on what size the spreadsheet was open on but i dont have access to those monitors to exactly what the height and width will be for those dimensions

Is there a way i can find out the height and width of the excel window maximised giving the screen size?

Thank You
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Try this;

Code:
Sub Test()
    Application.WindowState = xlMaximized
    strMsg = "Excel is now maximized"
    appWidth = Application.Width
    appHeight = Application.Height
    MsgBox strMsg & vbCrLf & "width= " & appWidth & vbCrLf & "height= " & appHeight
End Sub
 
Upvote 0
Hi

Tgis isn’t exactly what I want- i wat to be able to pass the dimensions of a screen size and then get what the size of the excel window would be if it was maximised

thanks
 
Upvote 0
I am not sure for what you are asking but, the following code may give you some details;

Code:
#If Win64 Then
    Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL] 
    Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL]  If

Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1
'
Sub Test2()
    Dim objWMI As Object
    Dim resultsWMI As Object
    Dim objMonitor As Object
    Dim monitorWidth As Double
    Dim monitorHeight As Double
    Dim monitorDiagonal As Double

    Set objWMI = GetObject("winmgmts:\\.\root\WMI")
    Set resultsWMI = objWMI.ExecQuery("Select * From WmiMonitorBasicDisplayParams")

    For Each objMonitor In resultsWMI
        monitorWidth = objMonitor.MaxHorizontalImageSize
        monitorHeight = objMonitor.MaxVerticalImageSize

        strMsg1 = "-Physical dimensions of your monitor is: " & monitorWidth & " cm x " & monitorHeight & " cm"
        monitorDiagonal = Format(((monitorWidth ^ 2 + monitorHeight ^ 2) ^ 0.5) / 2.54, "0.00")
        strMsg1 = strMsg1 & " (" & monitorDiagonal & " inches)"
    Next
    
    strMsg2 = "-Your current resolution is: " & GetSystemMetrics(SM_CXSCREEN) & " pixel x " & GetSystemMetrics(SM_CYSCREEN) & " pixel"
    
    appWidth = Application.Width
    appHeight = Application.Height
    strMsg3 = "-Excel's current window is: " & appWidth & " pixel x " & appHeight & " pixel"
    
    MsgBox strMsg1 & vbCrLf & vbCrLf & strMsg2 & vbCrLf & vbCrLf & strMsg3, vbInformation
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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