Userform doesn't appear until I click on the Worksheet

I am loading an userform through a button click and this userform is not showing up in the front until I click on the workbook. Excel icon keeps blinking and when I click on the worksheet, the blinking stopped and the userform appeared.

what could be the possible reason. It's strange because the same code works for other userforms.

FormattingForm.StartUpPosition = 0
FormattingForm.Left = Application.Left + (0.5 * Application.Width) 
                      - (0.5 * NewReportEntry.Width)
FormattingForm.Top = Application.Top + (0.5 * Application.Height) 
                     - (0.5 * NewReportEntry.Height)    
FormattingForm.Show

Upvotes: 1

Views: 1032

Answers (2)

Basic.Bear
Basic.Bear

Reputation: 151

It could be related to opening another application. For me, it was MS Word.

When I opened the form after opening Word, Excel would react as you described above. It would blink and I would only see the form after clicking on MS Excel.

Set WdDoc = WdApp.Documents.Open(WdDocPathOpen, ReadOnly:=True)
frmLeaseType.Show

When I started the form before opening Word, it would act as expected.

frmLeaseType.Show
Set WdDoc = WdApp.Documents.Open(WdDocPathOpen, ReadOnly:=True)

Upvotes: 0

Vityata
Vityata

Reputation: 43593

It really depends how you call your form. In your case, the cheapest & dirtiest solution would be something like this:

Public Sub TestMe()

    Dim FormattingForm As New UserForm1
    FormattingForm.StartUpPosition = 0
    FormattingForm.Left = Application.Left + (0.5 * Application.Width)
    FormattingForm.Top = Application.Top + (0.5 * Application.Height)
    FormattingForm.Show

End Sub

UserForm1 is the name of the Form in the VBEditor:

enter image description here

If you do not like being dirty and you understand some OOP, try one of this: https://www.vitoshacademy.com/vba-the-perfect-userform-in-vba/ https://rubberduckvba.wordpress.com/2017/10/25/userform1-show/

Or use the old-dirty trick in VBA, writing the code inside the form and calling it there.

Upvotes: 2

Related Questions