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
 
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 "*_*.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
No its working the same way as the older one if you see the image there are pdf's of reliance, tata power, u torrent with different pdf's name i need to move all the reliance pdf's in reliance folder all the tata power pdf's in tata power folder and all the u torrent pdf's in u torrent folder
 

Attachments

  • Screenshot_2024-01-07-16-16-49-50_99c04817c0de5652397fc8b56c3b3817 (1).jpg
    Screenshot_2024-01-07-16-16-49-50_99c04817c0de5652397fc8b56c3b3817 (1).jpg
    131.4 KB · Views: 3
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
here it works perfectly fine… you could try

If LCase(it.Name) Like "*.pdf" Then
 
Upvote 0
Solution
here it works perfectly fine… you could try

If LCase(it.Name) Like "*.pdf" Then
Yes the previous one is working i was doing a mistake in it its working perfectly fine now thank you so much you saved my time
 
Upvote 0
Yes the previous one is working i was doing a mistake in it its working perfectly fine now thank you so much you saved my time

I am having one more issue if a pdf is already in a folder it doesn't replace it it shows file isn't working end file. Can you help me with it
 
Upvote 0

Forum statistics

Threads
1,215,123
Messages
6,123,183
Members
449,090
Latest member
bes000

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