首页 > Excel专区 > Excel教程 >

excel获取屏幕分辨率的VBA代码

Excel教程 2021-11-13 11:28:00

 用下面的代码可以获取屏幕分辨率,需将其放入模块中运行。

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


标签: excel获取屏幕分辨率VBA代码用下面的

office教程网 Copyright © 2016-2020 https://www.office9.cn. Some Rights Reserved.