J
jerem
I'd like to use the code below (with some modification help from you) to
alter the names of a bunch of files that exist in a folder, however I'd like
to be able (I'm thinking you can use a message box to gather information for
MyPath = "C:\", but don't exactly know how to do that) to get the varying
path names from the user by allowing them to navigate through Explorer and
once doing so have another Message Box come up asking what prefix do you want
to add to the previous existing name, then have all the filenames changed
(ignore this code below: NewName = Left(OldName, Len(OldName) - 4) & "A" & i
& ".xls"., what I need here is a statement that accomplishes adding the
prefix the user just typed in to the previously existing name -- so, if the
previously existing name was 1. Exhibits, and the user typed in Tab, then the
new name would be Tab 1. Exhibits and every other file in the folder would
get that same prefix (Tab) throughout the file list.
In a nutshell - I want to add a prefix to every file in the folder with the
help of user input (where the files reside and what is the prefix you want to
add to the filename). I hope this is not confusing. Thanks for your help.
Sub ChangeFileNames()
Dim fs, i As Integer, OldName As String, NewName As String, MyPath As String
Set fs = Application.FileSearch
MyPath = "C:\"
With fs
.NewSearch
.LookIn = MyPath
.SearchSubFolders = False
.FileName = "*.*"
.FileType = msoFileTypeAllFiles
.Execute
For i = 1 To .FoundFiles.Count
OldName = .FoundFiles(i)
NewName = Left(OldName, Len(OldName) - 4) & "A" & i & ".xls"
Name OldName As NewName
Next i
End With
End Sub
alter the names of a bunch of files that exist in a folder, however I'd like
to be able (I'm thinking you can use a message box to gather information for
MyPath = "C:\", but don't exactly know how to do that) to get the varying
path names from the user by allowing them to navigate through Explorer and
once doing so have another Message Box come up asking what prefix do you want
to add to the previous existing name, then have all the filenames changed
(ignore this code below: NewName = Left(OldName, Len(OldName) - 4) & "A" & i
& ".xls"., what I need here is a statement that accomplishes adding the
prefix the user just typed in to the previously existing name -- so, if the
previously existing name was 1. Exhibits, and the user typed in Tab, then the
new name would be Tab 1. Exhibits and every other file in the folder would
get that same prefix (Tab) throughout the file list.
In a nutshell - I want to add a prefix to every file in the folder with the
help of user input (where the files reside and what is the prefix you want to
add to the filename). I hope this is not confusing. Thanks for your help.
Sub ChangeFileNames()
Dim fs, i As Integer, OldName As String, NewName As String, MyPath As String
Set fs = Application.FileSearch
MyPath = "C:\"
With fs
.NewSearch
.LookIn = MyPath
.SearchSubFolders = False
.FileName = "*.*"
.FileType = msoFileTypeAllFiles
.Execute
For i = 1 To .FoundFiles.Count
OldName = .FoundFiles(i)
NewName = Left(OldName, Len(OldName) - 4) & "A" & i & ".xls"
Name OldName As NewName
Next i
End With
End Sub