+ Reply to Thread
Results 1 to 5 of 5

When sheet is activated, execute macro in other sheet and return to sheet

  1. #1
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    When sheet is activated, execute macro in other sheet and return to sheet

    Hey all,

    I got problems, and hopefully someone in here can help me out

    The thing is that I, when activating worksheet "SetUp", I want to execute a code (showsheets) in the worksheet "Ark1".
    The code i want executed is:

    Please Login or Register  to view this content.
    and the code I use is:

    Please Login or Register  to view this content.
    At the moment, the macro is executed in the worksheet "SetUp" (the wrong sheet). I tried to activate "Ark1", execute code and return to "SetUp", but it didn't work. Please enlighten me Thanks!
    Attached Files Attached Files
    Last edited by timtim89; 04-16-2012 at 10:50 AM.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: When sheet is activated, execute macro in other sheet and return to sheet

    You're using the statement "With Worksheets("Ark1")", but that doesn't activate the worksheet, just sets it as the object you're currently working with, which is different.

    At the moment ShowSheets will always write to the active sheet - is this what you want it to do, or do you always want it to output to a set sheet? If the latter you'd be best off passing the sheet to the ShowSheets sub, something like this...

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: When sheet is activated, execute macro in other sheet and return to sheet

    Thanks for the quick assistance! Last thing: How do I avoid hidden sheets being listed? I tried to insert following line, but didn't work:

    Please Login or Register  to view this content.
    But almost there Thanks for the help so far!

    btw: your suggestion was absolutely right: I wish to get the output in the Set sheet.
    Last edited by timtim89; 04-16-2012 at 10:23 AM.

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: When sheet is activated, execute macro in other sheet and return to sheet

    Nearly right, but it's not the visibility of the target sheet you need to be testing ...

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: When sheet is activated, execute macro in other sheet and return to sheet

    Ah that makes sense. Thanks for the explanation. Raises my chances of figuring it out myself next time (:

    Problem solved. Reputation added

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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