|
|
|
|
|
|
Excel
|
Screen Resolution Check / Change
|
|
Ease of Use
|
Intermediate
|
Version tested with
|
2002
|
Submitted by:
|
Jacob Hilderbrand
|
Description:
|
This code will test the users screen resolution. If that resolution is not what you have specified in the code, then the user gets a warning message, along with the Windows dialog box used to change their resolution.
|
Discussion:
|
It is often desirable to have userw work with your program in a specified screen resolution, but it can be rude to simply change it using code as it could impact other programs with which the user works. With this code, the user is informed that they should use a certain resolution, and then gives the user the opportunity to change it via the Windows dialog box.
|
Code:
|
instructions for use
|
Option Explicit
Private Sub Workbook_Open()
Call VerifyScreenResolution
End Sub
Option Explicit
Private Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long
Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1
Sub VerifyScreenResolution(Optional Dummy As Integer)
Dim x As Long
Dim y As Long
Dim MyMessage As String
Dim MyResponse As VbMsgBoxResult
x = GetSystemMetrics(SM_CXSCREEN)
y = GetSystemMetrics(SM_CYSCREEN)
If x = 1024 And y = 768 Then
Else
MyMessage = "Your current screen resolution is " & x & " X " & y & vbCrLf & "This program " & _
"was designed to run with a screen resolution of 1024 X 768 and may not function properly " & _
"with your current settings." & vbCrLf & "Would you like to change your screen resolution?"
MyResponse = MsgBox(MyMessage, vbExclamation + vbYesNo, "Screen Resolution")
End If
If MyResponse = vbYes Then
Call Shell("rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,3")
End If
End Sub
|
How to use:
|
- Copy from Private Sub Workbook_Open() (above) to the first End Sub.
- Open your workbook.
- Hit Alt+F11 to open the Visual Basic Editor (VBE).
- Double-click the ThisWorkbook on the left, under your file's name.
- Paste the code into the code window at right.
- Copy from Sub VerifyScreenResolution(Optional Dummy As Integer) to the end of the code (above).
- Go back to the VBE.
- From the menu, choose Insert-Module.
- Paste into the code window at right.
- Save the file and close it.
|
Test the code:
|
- Make your screen resolution 1024x768.
- Open the workbook (nothing should happen).
- Close the workbook.
- Change your screen resolution to anything except 1024x768.
- Open the workbook. You should get a message warning you about your screen resolution.
- Press Yes to change your resolution, press No to keep your resolution as it is.
|
Sample File:
|
CheckScreenResolution.zip 7.49KB
|
Approved by mdmackillop
|
This entry has been viewed 224 times.
|
|