VBA/Excel/Access/Word/Application/Application Windows
Содержание
- 1 Center application
- 2 Make sure that the scroll bars and status bar are hidden and that the formula bar is displayed:
- 3 Set the window position and size
- 4 To change the values of the WindowState, Width, and Height properties of the Excel application window, you must explicitly reference the Application object
- 5 Zoom a form
- 6 Zooming a Window and Setting Display Options
Center application
Private Sub Workbook_Open()
Dim maxWidth As Integer
Dim maxHeight As Integer
Application.WindowState = xlMaximized
maxWidth = Application.Width
maxHeight = Application.Height
Call CenterApp(maxWidth, maxHeight)
End Sub
Sub CenterApp(maxWidth As Integer, maxHeight As Integer)
Dim appLeft As Integer
Dim appTop As Integer
Dim appWidth As Integer
Dim appHeight As Integer
Application.WindowState = xlNormal
appLeft = maxWidth / 4
appTop = maxHeight / 4
appWidth = maxWidth / 2
appHeight = maxHeight / 2
Application.Left = appLeft
Application.Top = appTop
Application.Width = appWidth
Application.Height = appHeight
End Sub
Sub scroll()
With Application
.DisplayScrollBars = False
.DisplayStatusBar = False
.DisplayFormulaBar = True
End With
End Sub
Set the window position and size
Sub win()
Dim myWindow1 As Window, myWindow2 As Window
Set myWindow1 = ActiveWindow
Set myWindow2 = myWindow1.NewWindow
With myWindow1
.WindowState = xlNormal
.Top = 0
.Left = 0
.Height = Application.UsableHeight
.Width = Application.UsableWidth * 0.25
End With
With myWindow2
.WindowState = xlNormal
.Top = 0
.Left = (Application.UsableWidth * 0.25) + 1
.Height = Application.UsableHeight
.Width = Application.UsableWidth * 0.75
End With
End Sub
To change the values of the WindowState, Width, and Height properties of the Excel application window, you must explicitly reference the Application object
Sub changeSize()
Application.WindowState = xlNormal
Application.Width = 600
Application.Height = 450
End Sub
Zoom a form
Private Sub UserForm_Initialize()
LabelZoom.Caption = ActiveWindow.Zoom
" Zoom
With ScrollBarZoom
.Min = 10
.Max = 400
.SmallChange = 1
.LargeChange = 10
.Value = ActiveWindow.Zoom
End With
" Horizontally scrolling
With ScrollBarColumns
.Min = 1
.Max = 256
.Value = ActiveWindow.ScrollColumn
.LargeChange = 25
.SmallChange = 1
End With
" Vertically scrolling
With ScrollBarRows
.Min = 1
.Max = ActiveSheet.Rows.Count
.Value = ActiveWindow.ScrollRow
.LargeChange = 25
.SmallChange = 1
End With
End Sub
Zooming a Window and Setting Display Options
Sub zoom()
ActiveWindow.Zoom = 150
End Sub