View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default 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