Renaming excel files

OfficeUser

Well-known Member
Joined
Feb 4, 2010
Messages
544
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Is it possible to write a macro that will open an excel file and then rename that file using the contents of a given cell? I am looking to do this with a lot of files.

For instance in opens a file called 12345.xls and in cell A2 it says Pumpkin Pie, the files is then saved as 'Pumpkin Pie.xls'

Even if it could be saved as another file.

Thanks.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I have this to do part of the task. I just need to figure out how to open, run this macro, and close each workbook in a folder.

Code:
Sub SaveAsCell()
Dim strName As String
On Error GoTo InvalidName
strName = Sheet1.Range("A1")
ActiveWorkbook.SaveAs Filename:="C:\RenamedFiles\" & strName
Exit Sub
InvalidName: MsgBox "Unable to rename"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,628
Members
452,933
Latest member
patv

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