+ Reply to Thread
Results 1 to 16 of 16

Save file as non-macro enabled and delete original file.

  1. #1
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Save file as non-macro enabled and delete original file.

    Hi all,

    This is kind of a follow up from previous question I had. Now that I’m happy with my level of protection of my workbook I would like to achieve the following.

    Once a certain date has passed I would like the workbook to to the following.

    - Delete 2x sheets Named “Parameters” & “Macro” (Macro is a splash sheet
    - Save the file as a non macro enabled workbook
    - Close and delete the macro enabled workbook
    - open the non macro enabled workbook.

    Before this file is saved a non macro enabled it will removed all formulas (I have a macro for this that I will call).

    I’m choosing this method instead of just locking users out of the file.

    Hope I’ve explained my self well enough and thanks for your time.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save file as non-macro enabled and delete original file.

    https://www.exceldome.com/solutions/...el-worksheets/

    Please Login or Register  to view this content.
    https://forum.ozgrid.com/forum/index...ithout-macros/

    Please Login or Register  to view this content.

    https://excelchamps.com/vba/delete-f..._Kill_Function

    Please Login or Register  to view this content.
    Last edited by Logit; 03-28-2022 at 02:20 PM.

  3. #3
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Re: Save file as non-macro enabled and delete original file.

    Thanks, but the saving doesn’t seem to work. I would like to save the new File on the same folder (path) as the macro enabled file.

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save file as non-macro enabled and delete original file.

    You'll need to edit this line so the path matches where you want to save :

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148
    Quote Originally Posted by Logit View Post
    You'll need to edit this line so the path matches where you want to save :

    Please Login or Register  to view this content.
    Yeah I tried that, I set a constant call mypath which is the file path of the workbook it’s seemed to work (no error pop up) but then wasn’t saved in that folder.

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Save file as non-macro enabled and delete original file.

    Re: "Before this file is saved a non macro enabled it will removed all formulas"
    Which sheets? All sheets left in the workbook?

  7. #7
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148
    Quote Originally Posted by jolivanes View Post
    Re: "Before this file is saved a non macro enabled it will removed all formulas"
    Which sheets? All sheets left in the workbook?
    Yes all sheet, formula just turn to values

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Save file as non-macro enabled and delete original file.

    Please Login or Register  to view this content.
    The .xlsx workbook will be the active workbook after you run this.
    You can't delete the .xlsm workbook from the new workbook because the .xlsx workbook has no macros.

  9. #9
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,224

    Re: Save file as non-macro enabled and delete original file.

    It's a bit confusing, but try it
    Please Login or Register  to view this content.
    Artik

  10. #10
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148
    Quote Originally Posted by Artik View Post
    It's a bit confusing, but try it
    Please Login or Register  to view this content.
    Artik
    Thanks I’ll try that!

  11. #11
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,224

    Re: Save file as non-macro enabled and delete original file.

    I would prefer the answer once you've tried. Then it would be known whether the macro works as expected or not.

    And please:
    1. do not quote entire statements of predecessors
    2. do not create new threads with the same or very similar problem.

    Artik

  12. #12
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148
    That has worked, I had to move the call for formula to value and unprotect to the top but is worked great. I just need to add deleting the Command button.

    Thanks so much!

  13. #13
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Save file as non-macro enabled and delete original file.

    The code from Post #8 did not work?

  14. #14
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Re: Save file as non-macro enabled and delete original file.

    I havent tried yet but i will and see which is quicker. Thank you

  15. #15
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,224

    Re: Save file as non-macro enabled and delete original file.

    Quote Originally Posted by jolivanes View Post
    The code from Post #8 did not work?
    In theory, it should work. However, in practice it is a bit different. The XLSX file (created with SaveAs), although it does not have macros anymore, the macros from the XLSM oryginal file are still active until the XLSX is closed. Because macros reference sheets that have been programmatically deleted, a runtime error occurs. Only after reopening the XLSX file will it be macro-free.
    In the attachment the file on which I conducted the tests. You will see the symptoms that I am talking about above when you run the Save_As_XLSX procedure. After the macro is finished, change the values anywhere in the workbook and try to save the workbook.
    That's why I created such a crazy code.

    Artik
    Attached Files Attached Files

  16. #16
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Save file as non-macro enabled and delete original file.

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

+ 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. Script/macro to save a copy as tab delimited text file and then close original file
    By Merlin803 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-02-2015, 01:34 PM
  2. [SOLVED] Save file as macro-enabled with path and file name from a cell
    By BRISBANEBOB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-12-2015, 11:51 PM
  3. Replies: 1
    Last Post: 09-05-2013, 02:39 PM
  4. Delete a Macro from the Copied File while Replicating the Original File
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-24-2011, 09:50 AM
  5. Macro to keep original file open, not 'save as' file
    By LonestarGuy in forum Excel General
    Replies: 4
    Last Post: 06-09-2010, 03:53 PM
  6. rename current file save and delete original
    By valve79 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-13-2006, 05:17 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