Determine the screen size using VBA in Microsoft Excel

Follow by Email

With the macro below you can return the screen size with the function GetSystemMetrics32.

Declare Function GetSystemMetrics32 Lib "User32" _
    Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

Sub DisplayMonitorInfo()
Dim w As Long, h As Long
    w = GetSystemMetrics32(0) ' width in points
    h = GetSystemMetrics32(1) ' height in points
    MsgBox Format(w, "#,##0") & " x " & Format(h, "#,##0"), _
    vbInformation, "Monitor Size (width x height)"
End Sub


Please follow and like us:

One thought on “Determine the screen size using VBA in Microsoft Excel

  1. This function returns number of pixels, not number of points. For my screen, I need to multiply this value by .78 to get number of points. The .78 comes from measuring the actual height of the screen in inches. I am looking for a way to determine the value for any monitor so I can compute appropriate coordinates for generated form displays

Leave a Reply

Your email address will not be published. Required fields are marked *

To avoid automated spam,Please enter the value *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>