+ Reply to Thread
Results 1 to 2 of 2

How to automatically run a macro when template opens, but not when the copy is opened.

  1. #1
    Registered User
    Join Date
    04-25-2015
    Location
    Pointe au Baril, ON
    MS-Off Ver
    2013
    Posts
    11

    How to automatically run a macro when template opens, but not when the copy is opened.

    Hi,

    I have an Excel 2013 workbook template that the user opens, and then must click on a shape to run a macro that assigns a unique name to the template copy file using a region code and the date, and also sets the date in cell ("N3:O3"). Apparently clicking the shape is sometimes overlooked, so I've been testing how to automatically run the macro when the template is opened using the AutoOpen feature. Initially, it works fine. The problem is that the macro stays with the newly named macro-enabled workbook and tries to run whenever it is opened. Maybe there is a way to restrict the macro to the original template or maybe it could be corrected by bypassing the code in the macro based on one of a couple of conditions. As of yet, I don't know how to write that code. The conditions could be:

    - if the file being opened is not the original template (*.xltm), then skip the code, or
    - if the date cell is not the default date, which apparently is 00-Jan-00, then skip the code

    Any ideas are greatly appreciated. I'm sure it must be a simple if/then thing, but programming doesn't like unspecific language!

    Thanks in advance for the help.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,751

    Re: How to automatically run a macro when template opens, but not when the copy is opened.

    It sounds like you have a Sub Workbook_Open, then you can add this line as the first line:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Substitute the actual template name for the red part.

    Edit: Changed = to <> Very important!!!
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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. macro that opens webpage and automatically prints it
    By glide2131 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-20-2014, 01:59 PM
  2. Apply formulas to Excel 2007 template automatically when opened
    By Excel_New in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-12-2011, 08:56 AM
  3. macro to automatically run when spreadsheet is opened
    By penfold in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2008, 08:52 AM
  4. [SOLVED] Have macro run automatically as soon as excel is opened.
    By Dtown Dawg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2006, 06:25 PM
  5. Replies: 1
    Last Post: 11-30-2005, 12:55 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