+ Reply to Thread
Results 1 to 15 of 15

VBA to force save as macro-enabled workbook

  1. #1
    Forum Contributor
    Join Date
    07-21-2018
    Location
    London, England
    MS-Off Ver
    Excel for Mac Version 16.15
    Posts
    117

    VBA to force save as macro-enabled workbook

    Hello,

    I have a macro enabled template workbook and I would like it to force the user to save the file as a macro-enabled workbook.

    I have found the following code and copied it into the 'This Workbook' module but it's still saving as a Excel Workbook file.

    Please Login or Register  to view this content.
    Any help would be greatly appreciated!

    Thank you!

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: VBA to force save as macro-enabled workbook

    Hi there,

    See if the following code does what you need:

    Please Login or Register  to view this content.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Forum Contributor
    Join Date
    07-21-2018
    Location
    London, England
    MS-Off Ver
    Excel for Mac Version 16.15
    Posts
    117

    Re: VBA to force save as macro-enabled workbook

    Hey Greg!

    Thank you so much for your help!

    Just a couple of questions if you wouldn't mind helping.

    When the file saves using this code, "xlsm.xlsm" is added to the end of the filename - is there a way to prevent this?

    Also, is there a way to write in a line of code to automatically set the file name to today's date in the format "dd.mm.yyyy"?

    And lastly, as this code automatically sets it to save as a macro-enabled workbook, I am having trouble saving it as a macro-enabled template in the first instance. The file type drop-down in the save window isn't giving me any other options now. Is there a way to override this code just this first time?

    Thank you!

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: VBA to force save as macro-enabled workbook

    Hi again,

    See if the following code does what you need:

    Please Login or Register  to view this content.
    The default file name will be today's date - I've set the date format as "yyyy-mm-dd" because files listed using this format will be displayed chronologically in File Explorer - if you prefer to use "dd-mm-yyyy" just change the above value.



    Hope this helps - as before, please let me know how you get on.

    Regards,

    Greg M


    P. S. I've deleted an incorrect suggestion about saving for the first time - I'll post a corrected version of it as soon as I can.
    Last edited by Greg M; 02-18-2019 at 10:46 AM. Reason: P. S. added

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: VBA to force save as macro-enabled workbook

    Hi again,

    To create and save the template for the first time:


    Open a new workbook

    Save the (empty) workbook as a template workbook using whatever name is appropriate

    Open the TEMPLATE WORKBOOK itself from within Excel - i.e. don't just click on its icon in File Explorer (that would open a "normal" workbook based on the template)

    Paste the code from my previous post into the ThisWorkbook VBA CodeModule of the template workbook

    Perform a "normal" Save on the template workbook (Use Ctrl+s or the Save icon on the Quick Access Toolbar)

    Close the template workbook


    Now click on the icon for the template workbook to open a new workbook based on the template and use the SaveAs routine (F12) to have the new workbook saved as a Macro-Enabled workbook named with today's date.


    Hope this helps - as always, please keep me informed.

    Regards,

    Greg M

  6. #6
    Forum Contributor
    Join Date
    07-21-2018
    Location
    London, England
    MS-Off Ver
    Excel for Mac Version 16.15
    Posts
    117

    Re: VBA to force save as macro-enabled workbook

    Hi Greg,

    Thanks again! The saving as a template workaround has worked a charm.

    However, the code to save with a file name of today's date isn't working annoyingly - the file name remains blank using both SaveAs and Save from the quick access toolbar. Do you know why this might be?

    Thank you!

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: VBA to force save as macro-enabled workbook

    Hi again,

    When I click on the template icon to open a new workbook based on the template, and then press F12, I see the Save As dialog box with the "File name" box pre-populated with today's date.

    Have I misunderstood your requirements?

    Regards,

    Greg M

  8. #8
    Forum Contributor
    Join Date
    07-21-2018
    Location
    London, England
    MS-Off Ver
    Excel for Mac Version 16.15
    Posts
    117

    Re: VBA to force save as macro-enabled workbook

    Hey Greg,

    No that's exactly what I want it to do so I don't know why its not working.

    The code is saved in the correct place - and the default save as macro-enabled workbook is still working.

    I'm opening the template file from file explorer and and trying save as as well as save from the quick access.



    I'll try on my home PC later and see if I get the same issue.

    Thanks!

  9. #9
    Forum Contributor
    Join Date
    07-21-2018
    Location
    London, England
    MS-Off Ver
    Excel for Mac Version 16.15
    Posts
    117

    Re: VBA to force save as macro-enabled workbook

    So I'm having the same issue on my home PC - the file name isn't auto-populating. I have attached the file in case I've done something wrong that I'm missing...

    When I do File > SaveAs on my home PC, I'm actually getting a method error on the following line of code;

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by benjhardie; 02-20-2019 at 05:29 AM.

  10. #10
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: VBA to force save as macro-enabled workbook

    Hi again,

    Try using dashes instead of full stops when specifying the date format:

    Please Login or Register  to view this content.
    I'm not seeing any error messages at this end.


    Keep me posted!

    Regards,

    Greg M

  11. #11
    Forum Contributor
    Join Date
    07-21-2018
    Location
    London, England
    MS-Off Ver
    Excel for Mac Version 16.15
    Posts
    117

    Re: VBA to force save as macro-enabled workbook

    Still nothing Is it working from your PC?

  12. #12
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: VBA to force save as macro-enabled workbook

    Hi again,

    Yes, I opened the workbook directly from your last post (i.e. I didn't download and then open it), changed the full stops to dashes in the date format constant, and then pressed F12.

    The Save As dialog box appeared immediately and the File name box was pre-populated with today's date.

    I can't really suggest anything else for the moment - please keep me posted.

    Regards,

    Greg M

  13. #13
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,338

    Re: VBA to force save as macro-enabled workbook

    Seems to me GetSaveAsFileName is the problem on a Mac.
    Take a look at this.
    https://www.rondebruin.nl/mac/mac016.htm
    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.

  14. #14
    Forum Contributor
    Join Date
    07-21-2018
    Location
    London, England
    MS-Off Ver
    Excel for Mac Version 16.15
    Posts
    117

    Re: VBA to force save as macro-enabled workbook

    Ah! It's working now (with dashes) - don't know why it didn't before. Thanks for all your help

  15. #15
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: VBA to force save as macro-enabled workbook

    Hi again,

    Thanks for all of your feedback - glad to hear that things are working correctly now.

    You're welcome - glad I was able to help.

    Regards,

    Greg M

+ 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. VB A to save as macro enabled workbook
    By syedmehdi in forum Excel General
    Replies: 5
    Last Post: 12-09-2014, 11:49 AM
  2. [SOLVED] Force Macros Enabled on Workbook Open
    By hutch@edge.net in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-10-2014, 05:42 AM
  3. [SOLVED] save sheet as macro enabled workbook using codes
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-29-2014, 02:23 PM
  4. [SOLVED] Set default Save-As parameter to Macro Enabled workbook
    By JimDandy in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-24-2013, 09:26 AM
  5. [SOLVED] VBA to save macro enabled workbook to regular workbook
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-15-2013, 09:41 PM
  6. [SOLVED] Issue with VBA - Save as macro enabled workbook - address problem.
    By galvinpaddy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-09-2012, 08:14 AM
  7. Replies: 1
    Last Post: 04-01-2011, 05:02 AM

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