Macro to Save Current File with Values at the end

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,992
Office Version
  1. 2019
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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

LazyBug

Board Regular
Joined
Feb 28, 2020
Messages
160
Office Version
  1. 2010
Platform
  1. Windows
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
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,992
Office Version
  1. 2019
Platform
  1. Windows
Many thanks for the help. Code works perfectly
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,992
Office Version
  1. 2019
Platform
  1. Windows
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
 

LazyBug

Board Regular
Joined
Feb 28, 2020
Messages
160
Office Version
  1. 2010
Platform
  1. Windows
Try replace
VBA Code:
wb.SaveAs wb.Path & "\" & NewName, wb.FileFormat
with
VBA Code:
wb.SaveAs wb.Path & "\" & NewName, 51
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,992
Office Version
  1. 2019
Platform
  1. Windows
Many Thanks for the amended code-It works perfectly
 

Forum statistics

Threads
1,141,069
Messages
5,704,111
Members
421,327
Latest member
Msh

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