楼主 wise |
Q:如何用VBA得到当前窗口及可用区域的高度及宽度? A:高度直接是Height,而宽度则直接是Width;但可用区域的高度及宽度,则比较少见。可用区域的高度是usableHeight,而可用区域宽度则是UsableWidth. 具体请看下面例子:
|
2楼 xyh9999 |
'调用API显示EXCEL主窗口位置及大小的例子: '请将下列的几个类型定义及函数定义放在VBA模块的顶部 '首次拷入代码后需保存一下工作簿再运行ShowExcelWindowsSize Public Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As Long, ByRef lpRect As RECT) As Long Sub ShowExcelWindowsSize() Dim hWnd As Long, uRect As RECT hWnd = FindWindow("XLMAIN", Application.Caption) GetWindowRect hWnd, uRect MsgBox "该excel窗口大小为:" & _ vbCrLf & "left:" & uRect.Left & _ vbCrLf & "right:" & uRect.Right & _ vbCrLf & "Top:" & uRect.Top & _ vbCrLf & "Bottom:" & uRect.Bottom & _ vbCrLf & "width:" & uRect.Right - uRect.Left & _ vbCrLf & "height:" & uRect.Bottom - uRect.Top End Sub |