Pdf movement to folder

Faiyaz

New Member
Joined
Jan 6, 2024
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hii can anyone help me how can i move multiple pdf from one folder to another folder using the starting name of pdf
Eg: There are 100 pdf file with the name (invoice_001 lane_inv, invoice_005 street_inv, payment_009 creek_inv) and so on i need to move all the pdf with invoice name to' Invoice' folder and all payment pdf to 'Payment' Folder. How can i do that can anyone explain me in detail as i don't have much idea about it
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You can do that with VBA. Are you familiar with that?
 
Upvote 1
Are all three folders in the same directory and do all folders already exist?
It is important to know how to run a macro from Excel.
 
Upvote 0
Are all three folders in the same directory and do all folders already exist?
It is important to know how to run a macro from Excel.
No i only have pdf's file with me i need to make folder to move that pdf pleaseee help me out as it will save a lot of my time everyday
 
Upvote 0
I can give you code but you have to read on the web for how to run a macro
 
Upvote 0
If you run this code, it will ask you to select the folder in which the pdf files are located. After selecting the folder, it will create your new folders and moves the pdf's to their destination folder.

VBA Code:
Sub jec()
 Dim srcPath, destFold, destPath, it
 With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show = 0 Then Exit Sub
    srcPath = .SelectedItems(1) & "\"
    destFold = Left(srcPath, InStrRev(srcPath, "\", Len(srcPath) - 1))
    With CreateObject("scripting.filesystemobject")
       For Each it In .getfolder(srcPath).Files
         If LCase(it.Name) Like "payment_*.pdf" Or LCase(it.Name) Like "invoice_*.pdf" Then
            destPath = destFold & StrConv(Split(it.Name, "_")(0), vbProperCase) & "\"
            If Not .folderexists(destPath) Then .createfolder destPath
            .movefile srcPath & it.Name, destPath & it.Name
         End If
       Next
    End With
 End With
End Sub
 
Upvote 0
I will try it tomorrow and get back to you if i need any suggestions
If you run this code, it will ask you to select the folder in which the pdf files are located. After selecting the folder, it will create your new folders and moves the pdf's to their destination folder.

VBA Code:
Sub jec()
 Dim srcPath, destFold, destPath, it
 With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show = 0 Then Exit Sub
    srcPath = .SelectedItems(1) & "\"
    destFold = Left(srcPath, InStrRev(srcPath, "\", Len(srcPath) - 1))
    With CreateObject("scripting.filesystemobject")
       For Each it In .getfolder(srcPath).Files
         If LCase(it.Name) Like "payment_*.pdf" Or LCase(it.Name) Like "invoice_*.pdf" Then
            destPath = destFold & StrConv(Split(it.Name, "_")(0), vbProperCase) & "\"
            If Not .folderexists(destPath) Then .createfolder destPath
            .movefile srcPath & it.Name, destPath & it.Name
         End If
       Next
    End With
 End With
End Sub
 
Upvote 0
Ok, waiting for your feedback. Good luck
 
Upvote 1

Forum statistics

Threads
1,215,097
Messages
6,123,077
Members
449,094
Latest member
mystic19

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