Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Renaming Workbooks
Quick question, how do you rename all of the workbooks whose name contains
the word "Jul" in a certain folder by replacing the "Jul" with "August"? -------- Thanks, Anony |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Renaming Workbooks
Hi Anony
Make a copy of the folder to test it You can create a loop through all files and use Name Change the path to the folder in the code 'Fill in the path\folder where the files are MyPath = "C:\Users\Ron\test" Sub Example() Dim MyPath As String, FilesInPath As String Dim MyFiles() As String, Fnum As Long 'Fill in the path\folder where the files are MyPath = "C:\Users\Ron\test" 'Add a slash at the end if the user forget it If Right(MyPath, 1) < "\" Then MyPath = MyPath & "\" End If 'If there are no Excel files in the folder exit the sub FilesInPath = Dir(MyPath & "*.xl*") If FilesInPath = "" Then MsgBox "No files found" Exit Sub End If 'Fill the array(myFiles)with the list of Excel files in the folder Fnum = 0 Do While FilesInPath < "" Fnum = Fnum + 1 ReDim Preserve MyFiles(1 To Fnum) MyFiles(Fnum) = FilesInPath FilesInPath = Dir() Loop 'Loop through all files in the array(myFiles) If Fnum 0 Then For Fnum = LBound(MyFiles) To UBound(MyFiles) On Error Resume Next Name MyPath & MyFiles(Fnum) As MyPath & _ Application.WorksheetFunction.Substitute(MyFiles(F num), "Jul", "August") On Error GoTo 0 Next Fnum End If End Sub -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Anony" wrote in message ... Quick question, how do you rename all of the workbooks whose name contains the word "Jul" in a certain folder by replacing the "Jul" with "August"? -------- Thanks, Anony |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Renaming Workbooks
Thank you!
Glad to be learning more VBA tricks by the day. ------ Cheers, Anony "Ron de Bruin" wrote: Hi Anony Make a copy of the folder to test it You can create a loop through all files and use Name Change the path to the folder in the code 'Fill in the path\folder where the files are MyPath = "C:\Users\Ron\test" Sub Example() Dim MyPath As String, FilesInPath As String Dim MyFiles() As String, Fnum As Long 'Fill in the path\folder where the files are MyPath = "C:\Users\Ron\test" 'Add a slash at the end if the user forget it If Right(MyPath, 1) < "\" Then MyPath = MyPath & "\" End If 'If there are no Excel files in the folder exit the sub FilesInPath = Dir(MyPath & "*.xl*") If FilesInPath = "" Then MsgBox "No files found" Exit Sub End If 'Fill the array(myFiles)with the list of Excel files in the folder Fnum = 0 Do While FilesInPath < "" Fnum = Fnum + 1 ReDim Preserve MyFiles(1 To Fnum) MyFiles(Fnum) = FilesInPath FilesInPath = Dir() Loop 'Loop through all files in the array(myFiles) If Fnum 0 Then For Fnum = LBound(MyFiles) To UBound(MyFiles) On Error Resume Next Name MyPath & MyFiles(Fnum) As MyPath & _ Application.WorksheetFunction.Substitute(MyFiles(F num), "Jul", "August") On Error GoTo 0 Next Fnum End If End Sub -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Anony" wrote in message ... Quick question, how do you rename all of the workbooks whose name contains the word "Jul" in a certain folder by replacing the "Jul" with "August"? -------- Thanks, Anony |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Renaming and saving workbooks but macro still deletes | Excel Worksheet Functions | |||
renaming | Excel Programming | |||
Renaming | Excel Programming | |||
Renaming Problems | Excel Programming | |||
Renaming within VBA | Excel Programming |