VBA to rename pdf files in directory

scalls

New Member
Joined
Mar 15, 2007
Messages
1
I have several thousand .pdf files that I have to rename and wanted to use excel and VBA to do this. I have to current name in column A and the new name in column B. I have been trying to use the code in the following post but it cannot find any files to rename.

http://www.mrexcel.com/board2/viewtopic.php?t=206491&highlight=rename

can anyone help with this code or figure out why it cannot find any files. This is my code:

Sub Find()

Dim i As Integer

With Application.FileSearch
.LookIn = "C:\Test"
.Filename = "Test*.*"
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With

End Sub

Thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi there,

Are they in the same directory? If not, you can use the Name function. Also, shy away from using FileSearch as it is being discontinued. Instead, use either the Dir() function or the FileSystemObject.

Can you have these files in different directories? Please post examples of your data. Say, 10-20 examples.
 
Upvote 0
Hey Zack :biggrin:

Apologies to the OP for going off on a slight tangent (although it is relevant to the post too!) but was the discontinuance of Application.FileSearch raised at the MS MVPs summit? I think Jon (Peltier) mentioned that it could give screwy results, but it has always provided a simple way to list files and I will rather miss it (as well as being a pain to track down all my code that uses it!). I was wondering what MS's reasons were.

Cheers Zack! Back on-topic now...
 
Upvote 0
Hey Zack :biggrin:

Apologies to the OP for going off on a slight tangent (although it is relevant to the post too!) but was the discontinuance of Application.FileSearch raised at the MS MVPs summit? I think Jon (Peltier) mentioned that it could give screwy results, but it has always provided a simple way to list files and I will rather miss it (as well as being a pain to track down all my code that uses it!). I was wondering what MS's reasons were.

Cheers Zack! Back on-topic now...

http://technet2.microsoft.com/Offic...09af-485b-b5ed-d4b879dcc8f61033.mspx?mfr=true

This feature was rarely used. Native operating system search functionality and MSN Desktop Search provide more functionality. The search feature in Microsoft Office Outlook 2007 and in the 2007 Office release enables users to search e-mail more quickly than the File Search feature.

Migration path: In 2007 Office release, users can search more quickly in Office Outlook 2007 as a replacement for searching e-mail, and can use the operating system’s native search functionality or MSN Desktop Search to find other types of files.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,690
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top