问题
Activewindow.UsableWidth gives me the width of the screen with the Vertical Scroll Bar's width included. Is there a way I can calculate the width of the Scroll Bar? I measured it by having one shape be UsableWidth and the other shape be what I actually can see, and the difference is the width of the Scroll Bar. I'm wondering if there's a way to automate it so it can be used by a user with a higher or lower resolution, and therefore smaller or larger Scroll Bar.
Thank you!
回答1:
If you are looking to find the value for the vertical scrollbar width, you can use a Windows API call:
Declare Function GetSystemMetrics32 Lib "user32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
Public Const SM_CXVSCROLL = 2
______________________________________
Sub ShowVScrollWidth()
Dim lVScrollWidth As Long
lVScrollWidth = GetSystemMetrics32(SM_CXVSCROLL)
Debug.Print lVScrollWidth
End Sub
(Adapted from the info on this page. More info on the available GetSystemMetrics parameters can be found at this MSDN page.)
来源:https://stackoverflow.com/questions/37491755/find-width-of-excel-scroll-bar