Mohammed Hashim
Mohammed Hashim

Reputation: 117

Display Excel on the primary monitor

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:

  1. If i open any Excel file and make it full screen in the main screen then close it, then open the userform it works fine!
  2. If i open any excel file and move it to the secondary screen then close it and open the userform, the problem occurs!

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

Answers (2)

Mohammed Hashim
Mohammed Hashim

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

Wiktor Stribiżew
Wiktor Stribiżew

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

Related Questions