+ Reply to Thread
Results 1 to 14 of 14

Enable Macros when workbook is created

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Enable Macros when workbook is created

    I use macros in one workbook (A) to create another workbook (B) from Template (C). Template (C) has macros as part of it's makeup. Specifically, there's a macro that's triggered by the Worksheet Activate of a particular sheet ("SheetSpecial").

    My problem is that after creation of B, B gets saved but remains open, A and C close without saving changes, but the Worksheet Activate macros in B don't work unless I close and reopen the workbook. How can I get them to be working from inception? I need this because my users will want to work on the workbook as soon as it's created.

    Thanks in advance,
    John
    Last edited by jomili; 11-17-2011 at 10:26 AM.

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Enable Macros when workbook is created

    Then you have to save the file in a location trusted by excel and save the workbook as .xlsm before activating it.

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Enable Macros when workbook is created

    I'm using 2003, so .xlsm isn't really an option.

  4. #4
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Enable Macros when workbook is created

    What code are you using for the save as?

    And does it work when the location is trusted?
    Please take time to read the forum rules

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Enable Macros when workbook is created

    Here's my macro for my initial save:
    Please Login or Register  to view this content.
    . Following this I do heavy manipulation to the workbook. At the end of things, I do a save and then close out the workbook that initiated everything:
    Please Login or Register  to view this content.
    I'm not familiar with "Trusting" a location. What do I have to do to make a location "Trusted" by Excel?

  6. #6
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Enable Macros when workbook is created

    Hi,

    You can read a little about it here

  7. #7
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Enable Macros when workbook is created

    Okay, I read over the article. The gist of it for me is this statement:
    Please Login or Register  to view this content.
    For my personal setup, "Open All Files In" is blank. I have no idea what it would be set up as for my users, who stretch across the length and breadth of Texas.

    On Excel Banter (http://www.excelbanter.com/showthread.php?p=964890), I found this from Gord Dibben:
    Please Login or Register  to view this content.
    So, where does that leave us?

  8. #8
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Enable Macros when workbook is created

    Upgrade to excel 2010

    Im really not sure then, maby someone else has the answer for this then.

  9. #9
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Enable Macros when workbook is created

    Thanks for trying. I'd LOVE to move up to 2010, but I work for state government. We'll probably move to 2010 in around 2015.

  10. #10
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Enable Macros when workbook is created

    The year is almost 2012, when you upgrade next 2010 wont even be sold

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Enable Macros when workbook is created

    Macros will run in the new workbook. The problem is you are running code from Workbook A and closing it. Once it is closed then any code in it will not run. You need a way to activate the specific sheet in the new workbook before A is closed.

    Add a procedure in the new workbook that is called from A, this code should close A & activate the sheet
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  12. #12
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Enable Macros when workbook is created

    Roy,
    I understand in theory, but not in practice. You're saying I should have a macro in B that is called from A, then when I close A the macros in B will be active. I'm not sure how to call a macro from the new workbook. Do I put "Run" before the macro name, or is there another trick?

  13. #13
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Enable Macros when workbook is created

    The only reason I can think of for the behaviour you describe, would be that you disable events somewhere along the line and they don't get reset.
    Remember what the dormouse said
    Feed your head

  14. #14
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Enable Macros when workbook is created

    And that's a good reason!

    I checked, and that was exactly what the problem was. I put "Enable Events" at the end of all my code, and VOILA! it worked just fine.

    So easy, once you know the problem. Thanks for pointing it out.

    Thanks everyone for your help on this one. I learned some neat stuff. And a special thanks to RomperStomper for going straight to the source of the problem to find a solution.

    God bless you, every one!

+ 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