Save Worksheet as new Workbook with Values and Formatting

Darbyshire

New Member
Joined
Feb 3, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello

I have created the following VBA module, which saves and dynamically names a new workbook which is fine, but I really need to save the active sheet on its own as values and formats only, so it pulls through the data but no formulas but retains all page formatting in the new workbook as well.

Still learning VBA as I go so be glad of any suggestions/help, please. Many Thanks

Sub saveValuesFormat()
'
' saveValuesFormat Macro
'

'
Dim strName As String
Dim companyFilepath As String

strName = Range("AJ1")
companyFilepath = "C:\Users\**************\*************\***************\***************\" & strName

ThisWorkbook.Sheets("ANALYSIS REPORT").Activate
ActiveSheet.Copy
Set tempWB = ActiveWorkbook

With tempWB
.SaveAs Filename:=companyFilepath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
.Close
End With
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi & welcome to MrExcel.
How about
VBA Code:
ThisWorkbook.Sheets("ANALYSIS REPORT").Copy
With ActiveWorkbook
   With .Sheets(1).UsedRange
      .Value = .Value
   End With
   .SaveAs Filename:=companyFilepath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
   .Close
End With
 
Upvote 0
Solution
Thanks that works perfectly, could you also please help me to understand how to make the code differentiate whether we want to save formats or not, as I have similar sheets where I just need to pull out the raw data without the formatting. I currently have a simple macro that saves the file as CSV, but sometimes I need to add additional sheets and formulas to that data at a later date so end up resaving in XLS format.

Be glad of any tips.

Many Thanks
 
Upvote 0
To remove formats you would just add this line
VBA Code:
   With .Sheets(1).UsedRange
      .Value = .Value
      .ClearFormats
   End With
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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