Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Remove VB code from saved Excel file

Posted on 2012-09-18
Medium Priority
Last Modified: 2012-09-18
My excel macro is executed from command line using Workbook_Open()

At the end of the macro, the template file from where the code is running, saves a output file with date time stamp.
But the output file has the code as well, and when I open the output file, Workbook_Open() executes again with error.
How can I save the output file with out copying over the VB code/macro?
Question by:kris_sk2012
LVL 34

Expert Comment

by:Rob Henson
ID: 38410127
Which version of Excel?

If using 2007 or later the original file will be an xlsm (macro enabled). If you save as an xls it will save without the macros.

Rob H

Author Comment

ID: 38410250
I'm using Excel 2010.
The code in the VB script that saves the new file is

 ThisWorkbook.SaveAs ThisWorkbook.Path & "\Report_" & getDateTimeStamp() & ".xls", XlFileFormat.xlExcel8

What needs to change above to save the workbook without macros or code carried over?

Expert Comment

ID: 38410349
Hi kris,

You should try copying the workbook and then saving the copied version which doesn't include the VB code. Please refer to the last post by "johnske" here:


LVL 36

Accepted Solution

Norie earned 2000 total points
ID: 38410514
Save the workbook as xlsx.
Application.DisplayAlerts = False
 ThisWorkbook.SaveAs ThisWorkbook.Path & "\Report_" & getDateTimeStamp(), XlFileFormat.xlOpenXMLWorkbook
Application.DisplayAlerts = True

Open in new window


Author Closing Comment

ID: 38410535
Works perfect!!!

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question