Move .pdf files from one folder to another

dwilson38550m

Board Regular
Joined
Nov 21, 2005
Messages
89
Hi is it possible to use a vba macro to move .pdf files from one folder to another on my c drive....there are 100 or so files...the only constant is that all end in .pdf (the name of the file itself will vary but all end in .pdf. Thanks in advance
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Here's a similar macro that assumes you have a single source folder that holds all the pdf files you want to move to an existing destination folder. Change the paths and folder names to suit. Note: if you are using a MAC the final path separator (here a " \ ") must be changed.
Code:
Sub MovePDFsToAnotherFolder()
Dim fso As Object, sourcePath As String, destPath As String
Dim Fldr As Object, f As Object, ct As Long
sourcePath = "C:\Users\Joe\Documents\Source Folder\"  'Change path and folder name to suit
destPath = "C:\Users\Joe\Documents\Destination Folder\"  'Change path and folder name to suit
Set fso = CreateObject("Scripting.FileSystemObject")
Set Fldr = fso.getfolder(sourcePath).Files
For Each f In Fldr
    If f.Name Like "*.pdf*" Or f.Name Like "*PDF*" Then
        ct = ct + 1
        f.Move destPath
    End If
Next f
If ct > 0 Then
    MsgBox ct & " pdf files have been moved"
Else
    MsgBox "No pdf files found in the source folder"
End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,942
Members
449,094
Latest member
teemeren

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