Repost: Get screen resolution

  • Thread starter Thread starter Craig
  • Start date Start date
C

Craig

A couple of weeks ago there appeared a way of retrieving the current screen
resolution using VBA. Unfortunately I didn't get a copy.
If anyone has it can they please repost?
 
Craig,

Here's a very simple solution posted by Chip Pearson some while back

Declare Function GetDeviceCaps Lib "gdi32" _
(ByVal hdc As Long, _
ByVal nIndex As Long) As Long
Declare Function GetDC Lib "user32" _
(ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" _
(ByVal hwnd As Long, _
ByVal hdc As Long) As Long

Const HORZRES = 8
Const VERTRES = 10

Function ScreenResolution()

Dim lRval As Long
Dim lDc As Long
Dim lHSize As Long
Dim lVSize As Long

lDc = GetDC(0&)
lHSize = GetDeviceCaps(lDc, HORZRES)
lVSize = GetDeviceCaps(lDc, VERTRES)
lRval = ReleaseDC(0, lDc)
ScreenResolution = lHSize & "x" & lVSize

End Function

Sub GetScreenSize()
Debug.Print ScreenResolution()
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Thanks, I think that was the one.
I remember trying it in a new workbook and it worked (and then I deleted the
workbook weeks later along with the only copy of the code)
Smart move?
 
Actually, I think this is the code Chip gave you

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

Sub AAA()
Debug.Print GetSystemMetrics(0&)
Debug.Print GetSystemMetrics(1&)
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top