VBA Workbook Focus not working

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
645
Good Morning,

I keep fighting this VBA refocus issue and I haven't been able to get it to work. Below is a section of code from a userform. The userform opens up with a button that shows the "administration" page in the workbook (i.e. a hidden page). Anyway, if I open any excel sheet before I open this workbook, this workbook will open correctly but when this userform unloads, the other workbook(s) will always be on top, i.e. the focus. I have to manually click this workbook to get the focus back on it.

A few things to note: This workbook, upon its opening code, is designed to hide the application (excel) and go straight into the userform. The user can click the button (code below) to get into the workbook. This same issue arises no matter which button (1, 2, or 3) I click on the userform. Below is just one of the buttons.

Thanks

Code:
Private Sub CommandButton3_Click()
On Error GoTo Helper
Dim name As String
name = ThisWorkbook.Sheets("Notes").Range("N4")
Sheet13.Activate
TryAgain:
    Pass = InputBox("Enter Password", "The Coding Sheets")
    If Pass = "" Then Exit Sub
    If Pass = CStr(Worksheets("Developer").Range("B23").Value) Then
        Sheets("Developer").Visible = True
        Sheets("Notes").Visible = True
        Sheets("Ports").Visible = True
        Sheets("Developer").Select
        Application.Visible = True
        ThisWorkbook.Activate
    Else
        MsgBox "Password incorrect, Please try again", vbCritical, name
        GoTo TryAgain
    End If
    Unload Me
    ThisWorkbook.Activate
    Exit Sub[\code]
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Watch MrExcel Video

Forum statistics

Threads
1,122,255
Messages
5,595,106
Members
413,970
Latest member
Hodg100

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top