+ Reply to Thread
Results 1 to 13 of 13

Activate a specific sheet when opening a workbook.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-11-2009
    Location
    Cape Town
    MS-Off Ver
    Microsoft 365
    Posts
    858

    Activate a specific sheet when opening a workbook.

    I am using the following code to activate a sheet named "Profit" but receive an error message when opening the workbook? The spelling is correct and there is a sheet named "Profit"?

    Sub GoToProfit()
        Application.ScreenUpdating = False
        Unload UserForm2
        Sheets("Profit").Activate
        Range("A1").Offset(1, 2).Select
    End Sub
    Thanks in advance

  2. #2
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: Activate a specific sheet when opening a workbook.

    What does the error message say? Is your userform still named "Userform2"?
    ~~LaffyAffy13~~

    If I have helped you solve your problem, please be sure to click at the bottom left of my post.

    Thanks.

  3. #3
    Forum Contributor
    Join Date
    06-11-2009
    Location
    Cape Town
    MS-Off Ver
    Microsoft 365
    Posts
    858

    Re: Activate a specific sheet when opening a workbook.

    Error message: "Application-defined or object-defined error" - It then highlights the code line:
    Sheets("Profit").Activate

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Activate a specific sheet when opening a workbook.

    It won't be able to activate the sheet if it is hidden. Also, sometimes sheet names can have leading or trailing spaces causing the error, for example it could be "Profit " or " Profit", etc. You'll want to make absolutely certain the sheet's name is correct. If the sheet is hidden, you'll need to unhide it before you can activate it.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: Activate a specific sheet when opening a workbook.

    What tiger said. If you still get the error, then I'm lost.

  6. #6
    Forum Contributor
    Join Date
    06-11-2009
    Location
    Cape Town
    MS-Off Ver
    Microsoft 365
    Posts
    858

    Re: Activate a specific sheet when opening a workbook.

    Thanks for your reply, but I did check the spelling and there are no issues there? I have just opened the file and don't get an error message and everything is working? This has happened before with other files so it seems to be intermittent? I have not changed anything so am really confused.

  7. #7
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: Activate a specific sheet when opening a workbook.

    Maybe the sheet was hidden the last time the file was saved? and now it's not?

  8. #8
    Forum Contributor
    Join Date
    06-11-2009
    Location
    Cape Town
    MS-Off Ver
    Microsoft 365
    Posts
    858

    Re: Activate a specific sheet when opening a workbook.

    No definitely not.

  9. #9
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: Activate a specific sheet when opening a workbook.

    Weird. I created my own version of your above sub and had no issues when opening the workbook it was in. So idk. Glad it randomly fixed itself though

  10. #10
    Forum Contributor
    Join Date
    06-11-2009
    Location
    Cape Town
    MS-Off Ver
    Microsoft 365
    Posts
    858

    Re: Activate a specific sheet when opening a workbook.

    The same problem has re-occurred this morning after I closed & re-opened the workbook? I did this often yesterday without any issues though? If I right-click the "Arrow button" the macro is assigned to, and then click on the drop-down list for "Macros In", It shows the following: 1. All Open Workbooks. 2. This Workbook. 3. ABC Costing Project.xlsm. I only have 1 workbook open which is ABC Costing Project.xlsm. Why does it show 2 AND 3 if "This Workbook" is ABC Costing Project.xlsm?

  11. #11
    Forum Contributor
    Join Date
    06-11-2009
    Location
    Cape Town
    MS-Off Ver
    Microsoft 365
    Posts
    858

    Re: Activate a specific sheet when opening a workbook.

    When I open Excel and Press [Alt] [F11], there are two projects named FUNCRES.XLAM and ATPVBAEN.XLAM in addition to VBAPROJECTS (Book1). I don't know where these projects (XLAM) come from? Could these projects be causing an intermittent problem and how do I delete them? When I click on ATPVBAEN.XLAM, it prompts for a password?
    Thanks in advance.

  12. #12
    Forum Contributor
    Join Date
    06-11-2009
    Location
    Cape Town
    MS-Off Ver
    Microsoft 365
    Posts
    858

    Re: Activate a specific sheet when opening a workbook.

    I found these under "Add Ins" and removed them but could they have caused a problem with the ribbon display when I had them open?

  13. #13
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Activate a specific sheet when opening a workbook.

    .xla and .xlam files are add-ins. They are VBA code that have been saved in that format and then added to your Excel in order to expand its functionality with custom code. They do not require that you enable macros in order for them to work. As such, it's possible that either one of them had a workbook_event routine that could have been triggered when you opened, closed, saved, or performed any other event that was causing problems. You'll only know for sure if the issues doen't happen again now that you have removed those add-ins.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA Script to open a specific File adn activate a specific sheet within that sheet.
    By Kramxel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-05-2013, 01:31 PM
  2. [SOLVED] Activate a nominated sheet when opening a workbook
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-10-2013, 03:00 AM
  3. Activate sheet name from other workbook
    By emina002 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-07-2012, 02:58 AM
  4. Loading a specific sheet in a workbook on opening Excel
    By LEEP2008 in forum Excel General
    Replies: 2
    Last Post: 09-24-2009, 03:56 PM
  5. Replies: 2
    Last Post: 03-21-2005, 08:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1