Reputation: 117
I have a Userform opens automatically when opening an excel file. It has some display problems, as the option buttons disappear when scrolling down the form. this problem only occurs when i have 2 monitors (main and secondary). I noticed these two scenarios:
So,my questions is:
Is there any way to force Excel to be opened as full screen in the main screen?
Upvotes: 3
Views: 3966
Reputation: 117
It seems that VBA is effected by the dimensions of the last opened Excel file,by dimensions i mean, if it's full screen or normal displayed and in which screen. The other problem that need to be considered is: if an Excel file was displayed on secondary screen, and this screen is bigger than the primary screen, then Application.Top, Application.Left will not successfully be able to get the application to the main screen, it needs to be displayed as normal first. My final code to solve my own questions is:
Application.Visible = True
Application.WindowsState=xlNormal
Application.Width =100
Application.Height =100
Application.Top = 0
Application.Left = 0
Application.WindowsState =xlMaximized
With UserForm2
.Height=Application.Height
.Width=Application.Width
End With
UserForm2.ScrollBars = fmScrollBarsVertical
UserForm2.KeepScrollBarsVisible = fmScrollBarsVertical
UserForm2.Zoom = 120
UserForm2.ScrollHeight = (120 * nq) + 120
UserForm2.Show vbModeless
Application.Visible = False
Upvotes: 0
Reputation: 627180
Add this to the Workbook_Open()
event procedure, and you'll be able to open the workbook in full-screen mode on the primary monitor.
Private Sub Workbook_Open()
Application.Top = 0
Application.Left = 0
Application.DisplayFullScreen = True
End Sub
Upvotes: 3