Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a task at work and I’m not sure how to do what I want to do. I mail merge tons of letters and must file them into respective folders.

I can move files fine using




Sub MOVEFILES()

    Dim strFolderA As String
    Dim strFolderB As String
    Dim strFile As String
    Dim Cnt As Long
    Dim test As String
    
    test = 9
    '//Change the path to the source folder, accordingly
    strFolderA = "C:\Users\dusto\Desktop\Test2\"
    
    '//Change the path to the destination folder, accordingly
    strFolderB = "C:\Users\dusto\Desktop\Test\"
    
    strFile = Dir(strFolderA & "*.*")
    
    Do While Len(strFile) > 0
        
        Cnt = Cnt + 1
        Name strFolderA & strFile As strFolderB & strFile
        strFile = Dir
    Loop
    
    MsgBox Cnt & " file(s) have been transfered to " & strFolderB, vbInformation
        
End Sub 



Now here’s the juicy part.

I have files named 2 ways

AB_######_name.pdf ‘where ###### is unique and
ABC_######_name.pdf ‘ where again ###### is unique


Our folder system is like this:
C:\AB_######_name\Correspondence\ ‘THIS IS THE TARGET FOLDER FOR THE LETTER or
C:\ABC_######_name\Correspondence\ ‘THIS IS THE TARGET FOLDER FOR THE LETTER




The ###### in the Folder Name would be correspond to the PDF filename.

Now how do I go ahead and move the file to the correct folders. Sometimes the correspondence folder is not created, so I have to create it manually. And I have multiple files in the folder that need to be filed. I'm not sure what to do.
Posted
Updated 22-Jan-14 11:14am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900