+ Reply to Thread
Results 1 to 4 of 4

Automatically generate Code for a worksheet created by a macro

  1. #1
    Registered User
    Join Date
    04-29-2008
    Posts
    2

    Automatically generate Code for a worksheet created by a macro

    Hi,
    This is my first post to this group, so here goes.

    I have a macro that reads from an array and then creates a new tab for each item in the array, it then sets up a template on each of the newly created tabs.

    My problem is that I want to add a very simple macro to each new tab as well.

    Please Login or Register  to view this content.
    I can do this manually but would really like to automate this portion as well as there could be 25 or more sheets created.

    Is this even possible.

    Please let me know if you need further clarification.

    Thanks,
    JT

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    You could create a template sheet with the macro and then use your code to create copies of this sheet which should also copy the macro as well.
    Martin

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello jthompson,

    Welcome to the Forum!

    I hope this reply isn't to late for you to use it. You can call the macro from the Workbook_SheetSelectionChange event in the VBA Module ThisWorkbook. Now you won't have to add the macro to each individual sheet.
    Please Login or Register  to view this content.
    How to Save a Workbook Event Macro
    1. Copy the macro using CTRL+C keys.
    2. Open your Workbook and Right Click on any Worksheet's Name Tab
    3. Left Click on View Code in the pop up menu.
    4. Press ALT+F11 keys to open the Visual Basic Editor.
    5. Press CTRL+R keys to shift the focus to the Project Explorer Window
    6. Press the Down Arrow Key until ThisWorkbook is highlighted in blue.
    7. Press the Enter key to move the cursor to the Code Window
    8. Paste the macro code using CTRL+V
    9. Save the macro in your Workbook using CTRL+S

    Sincerely,
    Leith Ross

  4. #4
    Registered User
    Join Date
    04-29-2008
    Posts
    2

    Thank you

    Putting it at the workbook level TOTALLY fixed the problem.

    Thanks!!!

+ 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