excel获取屏幕分辨率的VBA代码
- 2023-02-27
- 来源/作者: Wps Office教程网/ 菜鸟图库
- 239 次浏览
用下面的代码可以获取屏幕分辨率,需将其放入模块中运行。
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