Save a copy 'without VBA modules'

DonAndress

Active Member
Joined
Sep 25, 2011
Messages
365
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello.

I have a macro that contains multiple modules and lots of code lines and also many worksheets. Using VBA I'd like to create a copy of this file but I'd like to strip it completely off the code (modules) and also I'd like to save only 3 specific sheets out of all existing. This is to save drive space as this kind of archiving will be performed on a daily basis.

Right now I have:
ActiveWorkbook.SaveCopyAs Filename:=Path & FileName & ".xlsm"

but of course it saves an exact copy of the original file.


How can achieve all above?
Simple ".xls" at the end gives a corrupt file as an output.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi

".xlsm" can have macros, the m is for "macro enabled"

To save without macros use ".xlsx"
 
Upvote 0
Well actually I changed the extension to xlsx and I still get the error.
It says " Excel cannot open the file [...] because the file format or file extension is not valid."
 
Upvote 0
Hi

The extension ".xlsx" it the one for the spreadsheets without macros.

To save some sheets in a new workbook without macros I'd:

- copy the sheets to a new workbook
- save the new workbook as a workbook without macros

This is a simple example:

This code copies the sheets Sheet1, Sheet2 and Sheet4 from the active workbook to a new workbook, saves the new workbook as a workbook without macros and closes it.

Code:
Sub Test()

    ActiveWorkbook.Sheets(Array("Sheet1", "Sheet2", "Sheet4")).Copy
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:="c:\tmp\test.xlsx", FileFormat:=xlOpenXMLWorkbook
    Application.DisplayAlerts = True
    ActiveWorkbook.Close
End Sub

Please test.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top