显示一个CommandBar集中在Excel中使用VBA在屏幕上
使用下面的宏,您可以在屏幕上居中显示水平和垂直方向的CommandBar。
该宏还显示了如何使用功能GetSystemMetrics32获取屏幕尺寸。
Declare Function GetSystemMetrics32 Lib "User32" _ Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long Sub CenterCommandBar() Dim w As Long, h As Long w = GetSystemMetrics32(0) ' screenwidth in points h = GetSystemMetrics32(1) ' screenheight in points With CommandBars("MyCommandBarName") .Position = msoBarFloating .Left = w / 2 - .Width / 2 .Top = h / 2 - .Height / 2 End With End Sub