Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming and saving workbooks but macro still deletes shrek Excel Worksheet Functions 0 November 8th 05 05:43 PM
renaming No Name Excel Programming 1 October 11th 04 05:01 PM
Renaming ianripping[_66_] Excel Programming 3 May 22nd 04 12:02 PM
Renaming Problems Matt[_17_] Excel Programming 3 October 2nd 03 05:31 PM
Renaming within VBA Brent McIntyre Excel Programming 4 August 21st 03 02:10 AM


All times are GMT +1. The time now is 12:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"