Workbook_Open Sub regularly does not follow the instructions

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
516
Office Version
  1. 365
Platform
  1. Windows
Hi All, I have this very simple sub in the ThisWorkbook object.

VBA Code:
Option Explicit
Private Sub Workbook_Open()
    'Check last row count to determine risk levels
    Sheet5.Select
    lrow = Cells(Rows.Count, 1).End(xlUp).Row
    If lrow > 1000 Then
        MsgBox "You need to review formulas in DNCHY2 for risk levels"
    End If

    Application.Visible = False: frm_Login.Show
    Application.WindowState = xlMaximized
    LoginInstance = 0

    'Set the default import file in case it was changed at the last session
    Sheet1.Range("e41").Value = "Main-Report.csv"

    'clear previous error in race tracks
    Sheet25.Range("O2").Value = ""

End Sub

For some reason, on a regular basis, the workbook does not open on Sheet 5 as instructed. It opens on any other sheet, and usually the sheet that I do not want users to see.

These variables are declared elsewhere.
Public LoginInstance as Integer
Public lrow as Double.

What am I missing?

Thanks in advance

Jeff.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
The code:
VBA Code:
Sheet5.Select
will select the sheet whose codename is Sheet5. But the name of the sheet tab may be something different:
sheetname vs codename.PNG


Are both the Sheet Name and Sheet code name the same for sheet 5? If so, then most likely the userform,
VBA Code:
frm_Login.Show
could be changing the active sheet somehow. So I would put another Sheet5.Select at the end of the sub.
 
Last edited:
Upvote 0
hmmm..great thought cmowla. I will look into that. I didn't think of that. I only ever used sheet codename in my code because that solves a whole heap of referencing issues :)

just checked.... on the money cmowla. in the userform_active sub there is

VBA Code:
    Set sh = ThisWorkbook.Sheets("User_Management")
    sh.Visible = xlSheetVisible

which is one of the forms that opens up in the background.

What I don't understand though, is why this happens regularly, but not always? I don't want users to see this sheet at all.

Any suggestions?
 
Upvote 0
Hi there

What happens if you change

VBA Code:
Sheet5.Select

to

VBA Code:
Sheet5.Activate
 
Upvote 0
If you don't want users to see it, why are you making it visible?
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

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