用下面的代碼可以獲取屏幕分辨率,需將其放入模塊中運行。
1.按Alt+F11打開VBA編輯器。
2.單擊菜單“插入→模塊”,在模塊中輸入下列代碼并運行:
Declare Function GetSystemMetrics32 Lib "user32" _
Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
Sub DisplayMonitorInfo()
Dim X As Long, Y As Long
X = GetSystemMetrics32(0) ‘ 寬度(像素)
Y = GetSystemMetrics32(1) ‘ 高度(像素)
MsgBox "屏幕分辨率為:" & X & " × " & Y & " 像素"
End Sub