Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename pdf file (random name) in multiple folders

Status
Not open for further replies.

undefined0

Technical User
Oct 23, 2006
1
US
Hi all,

Please help me how to write VBA code in Excel to rename pdf file in multiple subfolders (same name under each directory) to a define name. Folder structures are of follow:

C:\Test\A\Apple\F1\random123.pdf >>>>>rename file to>>>>>>>> F1_Apple.pdf
C:\Test\A\Adam\F1\randomxyz.pdf >>>>>rename file to>>>>>>>> F1_Adam.pdf
C:\Test\B\Baby\F1\123456.pdf >>>>>rename file to>>>>>>>> F1_Baby.pdf
C:\Test\B\Banana\F1\abfdefg.pdf >>>>>rename file to>>>>>>>> F1_Banana.pdf

I can define the path of the F1 folders (not the pdf file name though) in an Excel column. I can also define which name to rename to in another corresponding column. Also, there is only 1 file in each of the F1 folders.

Thank you for your help.
 
Which version of Excel? how you do things with the file object depends on the version of VBA.
if 2007 or 2010 look at File system object

Friendly "posting" advise for someone been here a decade or more.
tip: start it with "Excel 2007: Rename pdf file (random name) in multiple folders"
Also give some code you have as a start so we can save us all a lot of time :)
here is a starting point
Put your code inside [ code ] .... [ /code ] tags
Code:
Public Function RenamePDFile(Filename)
    ' set file system object
    Set fs = CreateObject("Scripting.FileSystemObject")

    ' need random function 1 to 50, look up RND in help
    RandomNumber = Int((50 * Rnd) + 1)
' if you want characters in the name, look at chr(somenumber) '65 = Capital"A"
    
    RenameFile = FinalResult
End Function

DougP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top