Hi All
I am new to Excel VBA and would appreciate any help I can get!
I am trying to prefix all the files in a folder ready for archiving. I want if possible to input the folder the files are located in and also the prefix that should be added by inputboxes.
Is this possible and if so can anyone show me how this is done?![]()
Last edited by stawil; 06-10-2011 at 09:00 AM.
Hi,
Please give us more information
let your folder will be at path c:\files
- would you like to list all files from that directory ?
- would you like to change names of those files / move to other place /delete them
- what kind of files *.xls ? *.txt ? *.* you have
Give more info and I think someone will be able to do everthing You will need.
Best Regards
Sorry about the lack of detail but the following are the files etc I would wish to change.
Path: F:\General\Quarterly Absence Report\"Folder Name"\*.*files
I would wish to use the exsisting file name then prefix all the files within the "Folder Name" with prefix entered e.g.
F:\General\Quarterly Absence Report\Fin Year 200708\April.xls
F:\General\Quarterly Absence Report\Fin Year 200708\Absence Stats.xls
would be renamed as
F:\General\Quarterly Absence Report\Fin Year 200708\200708 April.xls
F:\General\Quarterly Absence Report\Fin Year 200708\200708 Absence Stats.xls
I would like to be able to have an input box for the folder and prefix if possible and all the files are either .xls or .doc.
Hope this helps, not too good and explaining things, but appreciate your help.
I have been trying to alter a solution given for renaming a file with a suffix and was wondering if this code could be altered to rename existing files by prefixing the file name with a variable input whilst leaving them in exactly the same location. I am looking to rename only.
I do not follow or understand the below code enough to alter to my requirements, but hope that someone out there (hopeful the person who wrote the original code) can help me........please!!!
Code:
Sub RenameFiles()
Dim FileName As String
Dim FilePath As String
Dim NewFileName As String
Dim RegExp As String
Dim vFolder As Variant
FilePath = "C:\Fin Year 200809\"
' Set RegExp = CreateObject("VBScript.RegExp")
' RegExp.IgnoreCase = True
' RegExp.Pattern = "(.+)(O\-.+)(\..*)"
RegExp = InputBox("Please enter your required prefix: e.g. 200708")
For Each vFolder In Array("Craig Clement", "Support Staff")
FileName = Dir(FilePath & vFolder & "*.*")
While FileName <> ""
If RegExp.Test(FileName) Then
NewFileName = RegExp.Replace(FileName, "$1$3")
Name FilePath & vFolder & FileName As FilePath & vFolder & NewFileName
End If
FileName = Dir()
Wend
Next vFolder
End Sub
Code/
Code:
I'm sorry that I'm not explained provoded script, but I hope that presented solution will cover your need.
Please check examples in attached zip file.
p.s. there no prefix validation for now, so you should tape only alfanumerical symbols correct for windows path
Best Regards
maczaq.....thank you so much........works a treat and also response was so quick..again thank you.......Best Regards
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks