Macro to Save Current File with Values at the end

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have a macro to copy and paste all the data as values

I would like a macro to save the file to contains values just before .xls

eg BR1 Stats - Dec 2020.xls

need this to save as BR1 Stats - Dec 2020 Values.xls using a macro

It would be appreciated if someone can assist me
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
If I've get your goal correctly:
VBA Code:
Sub h()
Dim wb As Workbook, OldName$, NewName$
Set wb = ActiveWorkbook
    OldName = wb.Name
    NewName = Left(OldName, InStrRev(OldName, ".") - 1)
    NewName = NewName & " Values.xls"

    wb.SaveAs wb.path & "\" & NewName, wb.FileFormat
End Sub
 
Upvote 0
Many thanks for the help. Code works perfectly
 
Upvote 0
I have another file which it an .xlsm file and want a macro to save it as a .xlsx file

i tried to amend your code,but cannot get it to work


Code:
 Sub saveas_XLSX()
ActiveWorkbook.Save

Dim wb As Workbook, OldName$, NewName$
Set wb = ActiveWorkbook

    OldName = wb.Name
NewName = Left(OldName, InStrRev(OldName, ".xlsm") - 1)
    NewName = NewName & " .xlsx"

    wb.saveas wb.Path & "\" & NewName, wb.FileFormat
    End Sub



I get error message below

1611832572000.png



kindly amend my code
 
Upvote 0
Try replace
VBA Code:
wb.SaveAs wb.Path & "\" & NewName, wb.FileFormat
with
VBA Code:
wb.SaveAs wb.Path & "\" & NewName, 51
 
Upvote 0
Many Thanks for the amended code-It works perfectly
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,924
Members
448,533
Latest member
thietbibeboiwasaco

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