log*_*gan 4 excel vba excel-2003 excel-vba screen-resolution
我有一个Excel 2003宏来根据屏幕分辨率调整我的屏幕缩放.
Sub Macro1()
Dim maxWidth As Long, myWidth As Long
Dim myZoom As Single
maxWidth = Application.UsableWidth * 0.96
'I use r because upto r i have macro buttons
myWidth = ThisWorkbook.ActiveSheet.Range("r1").Left
myZoom = maxWidth / myWidth
ActiveWindow.Zoom = myZoom * 100
End Sub
Run Code Online (Sandbox Code Playgroud)
当我在Excel 2003中尝试时,按钮大小及其标题不能正确缩放.而且Application.UsableWidth总是返回1026的宽度无论是屏幕分辨率1024*768或1366*768.有任何想法吗?
如果在任何系统屏幕分辨率下打开,我希望Excel工作表适合宽度
小智 9
Sheets(1).Range("a1:AC1").Select
ActiveWindow.Zoom = True
Run Code Online (Sandbox Code Playgroud)
是的,这就是所需要的.这将根据屏幕分辨率调整缩放级别.有关详细信息,请参阅以下链接: - http://optionexplicitvba.blogspot.sg/2011/10/one-size-fits-all.html
您可以将此 Windows API 调用添加到您的代码中,该代码可以确定屏幕分辨率。
Private Declare PtrSafe Function GetSystemMetrics Lib "USER32" _
(ByVal nIndex As Long) As Long
Sub Macro1()
Dim maxWidth As Long
Dim myWidth As Long
Dim myZoom As Single
maxWidth = GetSystemMetrics(0) * 0.96
myWidth = ThisWorkbook.ActiveSheet.Range("R1").Left
myZoom = maxWidth / myWidth
ActiveWindow.Zoom = myZoom * 100
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18761 次 |
| 最近记录: |