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
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,549
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

Darbyshire

New Member
Joined
Feb 3, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,549
Office Version
  1. 365
Platform
  1. Windows
To remove formats you would just add this line
VBA Code:
   With .Sheets(1).UsedRange
      .Value = .Value
      .ClearFormats
   End With
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,549
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,595
Messages
5,625,697
Members
416,128
Latest member
WarJamAnd

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
Top