Excel VBA to export and save sheet as a new workbook without formulas

Status
Not open for further replies.

emadhamrawi

New Member
Joined
Nov 11, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
I need a VBA code that helps me export an excel sheet and save it as an excel workbook without formulas.
 
Welcome to the MrExcel Message Board!

Try the following macro in a standard module. It is only three lines actually, but looks more with comments. Follow the comments to understand how it works.

VBA Code:
Sub saveSheetWithoutFormulas()
    ' Copy the active sheet
    ' This automatically creates a new workbook
    ' with the sheet copied in it
    ActiveSheet.Copy
   
    ' Active sheet is now the copied sheet in the new workbook
    ' Following will change formulas to values
    ActiveSheet.UsedRange.Value = ActiveSheet.UsedRange.Value
   
    ' Open a file save dialog to save the new workbook
    ' If you know where to save with a predefined file name
    ' then you can use ActiveWorkbook.SaveAs "C:\FolderPath\FileName.xlsx"
    Application.GetSaveAsFilename

End Sub

If you want to make it work with a certain worksheet which is not supposed to be the active sheet when you run the code, then you need to change the first line, ActiveSheet.Copy, with the following by using the actual sheet name instead of "Sheet1".

VBA Code:
Worksheets("Sheet1").Copy
Welcome to the MrExcel Message Board!

Try the following macro in a standard module. It is only three lines actually, but looks more with comments. Follow the comments to understand how it works.

VBA Code:
Sub saveSheetWithoutFormulas()
    ' Copy the active sheet
    ' This automatically creates a new workbook
    ' with the sheet copied in it
    ActiveSheet.Copy
   
    ' Active sheet is now the copied sheet in the new workbook
    ' Following will change formulas to values
    ActiveSheet.UsedRange.Value = ActiveSheet.UsedRange.Value
   
    ' Open a file save dialog to save the new workbook
    ' If you know where to save with a predefined file name
    ' then you can use ActiveWorkbook.SaveAs "C:\FolderPath\FileName.xlsx"
    Application.GetSaveAsFilename

End Sub

If you want to make it work with a certain worksheet which is not supposed to be the active sheet when you run the code, then you need to change the first line, ActiveSheet.Copy, with the following by using the actual sheet name instead of "Sheet1".

VBA Code:
Worksheets("Sheet1").Copy
How can add date or time in name of new excel workbook that exported with this code?
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
How can add date or time in name of new excel workbook that exported with this code?

Duplicate to: Excel VBA to export and save sheet as a new workbook that new workbook's name contains current date or time without formulas,.

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this old thread so please continue in the linked thread. If you do not receive a response, you can "bump" it by replying to it yourself, though we advise you to wait 24 hours before doing so, and not to bump a thread more than once a day.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,098
Messages
6,170,100
Members
452,301
Latest member
QualityAssurance

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