VBA Workbook Focus not working

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
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]
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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
Back
Top