MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Screen size


Posted by Stevie Windows on July 11, 2001 8:53 AM

I want to be able to insert a function into the Workbook_Open() subroutine that will discern what dimensions the viewer's monitor is set to, if the display is set to less than 1024x765: eg. it's set to 800x600, I want a message to flash recommending the user that the project is best viewed at 1024x765 or greater. Then I want the messagebox to offer the option "set monitor to 1024x765? Yes / No". If the user chooses Yes, I would ideally like to offer them the opportunity to set it back to the original resolution on closing the project. Any ideas??


Posted by stevie windows on July 11, 2001 8:55 AM

Silly me, I also need to know the code to set the monitor resolution, in case that wasn't clear.

Posted by Dax on July 11, 2001 9:18 AM

Hello,

You need API calls. Try this: -

Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long
Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1

Sub GetScreenSize()
Dim x As Long, y As Long, sYourMessage, iConfirm As Integer
x = GetSystemMetrics(SM_CXSCREEN)
y = GetSystemMetrics(SM_CYSCREEN)
If x < 1024 And y < 768 Then
sYourMessage = "This screen is best viewed at 1024 x 768." & vbCrLf
sYourMessage = "Would you like to change the resolution?"
iConfirm = MsgBox(sYourMessage, vbExclamation + vbYesNo, "Screen Resolution")
If iConfirm = vbYes Then
'Change screen settings
End If
End If
End Sub


However, it doesn't change the screen resolution. If you change the screen resolution without testing it first it can completely bugger up the monitor. Maybe, you could just suggest that the user changes it themselves?

Regards,
Dax.


Posted by Ivan F Moala on July 11, 2001 1:38 PM

Here is a mode to Dax's code which gives the user
access to change the display....safer way as Dax
has commented.

Sub GetScreenSize()
Dim x As Long, y As Long, sYourMessage, iConfirm As Integer
x = GetSystemMetrics(SM_CXSCREEN)
y = GetSystemMetrics(SM_CYSCREEN)
If x < 1024 And y < 768 Then
sYourMessage = "Current screen size is " & x & " x " & y & vbCrLf
sYourMessage = sYourMessage & "This screen is best viewed at 1024 x 768." & vbCrLf
sYourMessage = sYourMessage & "Would you like to change the resolution?"
iConfirm = MsgBox(sYourMessage, vbExclamation + vbYesNo, "Screen Resolution")
If iConfirm = vbYes Then
'Change screen settings
Call Shell("rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,3")
End If
End If
End Sub

Ivan