![]() |
How do you rename Multiple files using text from a cell in the file?
I could use some help writing my macro for excel. This is what I have:
1) I have 3 files in C:/sample named 1.xls, 2.xls, and 3.xls (this varies from 2 - 30 files) 2) I need to save each one using text in cell E28 I would like: 1) An input prompt when Macro starts to ask how many files. 2) Then the Macro to run through all numbered files saving the file using what text is in cell E28 as the new file name. I have been able to get it to do the first file, but I can't get the variable to change on the second and additional files. Thanks for your Help. |
How do you rename Multiple files using text from a cell in the file?
Try this
Select the files you want in the open dialog that popup (use the Ctrl key) It use E28 in the first sheet of each workbook mybook.SaveAs Sheets(1).Range("E28") & ".xls" Sub Example() Dim mybook As Workbook Dim N As Long Dim MyPath As String Dim SaveDriveDir As String Dim FName As Variant SaveDriveDir = CurDir MyPath = "C:\Data\" ChDrive MyPath ChDir MyPath FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls", _ MultiSelect:=True) If IsArray(FName) Then Application.ScreenUpdating = False For N = LBound(FName) To UBound(FName) Set mybook = Workbooks.Open(FName(N)) mybook.SaveAs Sheets(1).Range("E28") & ".xls" mybook.Close False Next End If ChDrive SaveDriveDir ChDir SaveDriveDir Application.ScreenUpdating = True End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "RandyR" wrote in message oups.com... I could use some help writing my macro for excel. This is what I have: 1) I have 3 files in C:/sample named 1.xls, 2.xls, and 3.xls (this varies from 2 - 30 files) 2) I need to save each one using text in cell E28 I would like: 1) An input prompt when Macro starts to ask how many files. 2) Then the Macro to run through all numbered files saving the file using what text is in cell E28 as the new file name. I have been able to get it to do the first file, but I can't get the variable to change on the second and additional files. Thanks for your Help. |
All times are GMT +1. The time now is 04:25 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com