Question : VBA code to rename file based on cell value

Does anyone know of a way to rename a file folder based on a cell value in excel 2007. I have several file folders with one spreadsheet in each one. I would like to rename the file folder based on a cell value within that spreadsheet in that file.
Thanks

Answer : VBA code to rename file based on cell value

You can rename a folder using the Name statement.

Dim sOldPath As String, sNewName As String
sOldPath = ActiveWorkbook.Path
sNewName = ActiveWorkbook.Worksheets(1).Range("A1")        'Desired name for the folder
ActiveWorkbook.Close SaveChanges:=False         'You must close the workbook before renaming its parent folder
Name sOldPath As "C:\My Documents\" & sNewName
Renames folder ABC to the contents of cell A1 in the first worksheet in the active workbook.


Brad
Random Solutions  
 
programming4us programming4us