+ Reply to Thread
Results 1 to 16 of 16

Macro that activates sheet upon opening of a file

  1. #1
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Macro that activates sheet upon opening of a file

    Hi Guys!

    It probably does not get any simpler than this but I would like to ask the following question:

    I have a workbook that I would like to select a certain sheet upon opening.

    The code I have taken from the internet is:

    Please Login or Register  to view this content.
    If I manually activate it while I have the workbook open it works! However when I close and open the workbook up again, the macro should activate and select the instructions sheet, however it states "Worksheet does not exist"

    Please help me out!

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Macro that activates sheet upon opening of a file

    Hi,

    I would recommend specifying the workbook as well
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro that activates sheet upon opening of a file

    Check the actual sheet name spelling VERY carefully
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,911

    Re: Macro that activates sheet upon opening of a file

    Where does your code reside? Is it in ThisWorkbook module? If it is, it should have "Private" in front of Sub (which is added automatically)

    Make sure it's in correct module.

    0.JPG

    Edit: Alternate to what xlnitwit wrote, you can use "Me." in front of Worksheets as well.
    Since the code reside on the workbook itself, it will confine it to the workbook context.

    Another thing you can do, is to use sheet index (to right of the sheet name/caption) in Project pane.
    Last edited by CK76; 08-22-2017 at 11:51 AM. Reason: See Edit:
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  5. #5
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Re: Macro that activates sheet upon opening of a file

    It is in this workbook and I have updated it now to:

    Please Login or Register  to view this content.
    + It is in this workbook! And it is still not working....

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro that activates sheet upon opening of a file

    Yes it does
    When before you close the attached file, change something and save it with the other sheet active then open it again
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Re: Macro that activates sheet upon opening of a file

    Oh yeah, it wasn't working due to me protecting the workbook. However it does keep saying WorkSheet does not exist upon opening!

  8. #8
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Re: Macro that activates sheet upon opening of a file

    SO this should be able to solve the problem but now it actually does not work. The file needs to be protected upon opening.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Re: Macro that activates sheet upon opening of a file

    So it only works when the workbook is unprotected, so this should work right?

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Macro that activates sheet upon opening of a file

    Did you try this one ?

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  11. #11
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Re: Macro that activates sheet upon opening of a file

    Also does not work unfortunately

  12. #12
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro that activates sheet upon opening of a file

    Rather than trying to open workbook in the correct sheet, save it with the correct sheet activated:

    In ThisWorkbook module
    Please Login or Register  to view this content.

  13. #13
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Macro that activates sheet upon opening of a file

    It should be ThisWorkbook for all items
    Please Login or Register  to view this content.

  14. #14
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Macro that activates sheet upon opening of a file

    I guess it's more a workbook thing because tested it on a protected workbook and works just fine.

    protected a woorkbook with this

    Please Login or Register  to view this content.
    Put this in ThisWorkbook

    Please Login or Register  to view this content.
    Activated a different sheet and saved and closed.

    After reopening desired sheet was selected without any problem.

    Not much more we can do i think.

    Maybe it's possible to post the workbook involved so we can test ?

  15. #15
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Re: Macro that activates sheet upon opening of a file

    It works! Thank you all very much

  16. #16
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Macro that activates sheet upon opening of a file

    Glad you got it running.
    Thanks for rep+.

+ 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] Application.Sumif funciton activates the other sheet tab
    By ImranBhatti in forum Excel General
    Replies: 3
    Last Post: 01-18-2017, 07:07 AM
  2. How to create a macro that 'activates' a filter on another sheet.
    By liamfrancis2013 in forum Excel General
    Replies: 6
    Last Post: 05-11-2016, 10:55 AM
  3. [SOLVED] Macro activates in wrong sheet
    By SoothSailor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2015, 12:17 PM
  4. Replies: 2
    Last Post: 05-31-2014, 02:05 AM
  5. Automatic updating of cells when sheet activates
    By popperm1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-05-2013, 12:54 PM
  6. Opening files macro help (forcing directory, opening a tsv file)
    By NukedWhale in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2010, 03:07 PM
  7. Copy a sheet and save as new file, without opening the file
    By Chinnick in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-13-2009, 05:00 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