Consulting

Results 1 to 5 of 5

Thread: Copy .pdf files from one location to a new folder based on a list of cell

  1. #1

    Copy .pdf files from one location to a new folder based on a list of cell

    1st time poster and VBA newby. I'm looking for a macro to copy a set .pdf files to a new folder(to be created if not already made) corresponding to the person they are assigned to. I have a snip below to show the columns(D&K). Right now we have all the IWP files matched with a similarly named .pdf in a folder(X:\03_IWP\IWP pdf) and I am looking to copy them into a new folder based on the Superintendent in another location(X:\03_IWP\Superintendent).

    Thank you for any help you can give!

    Currently using excel 2016

    Annotation 2019-12-04 102451.jpg

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    welcome to the forum.

    is it that you want to copy (for D2) X:\03_IWP\IWP pdf\IWAA05C11000-000.pdf to X:\03_IWP\Superintendent\Jorge Rodriguez\IWAA05C11000-000.pdf
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    if my guess is correct, you can try this:

    Sub vbax_66359_copy_files()
    
        Dim sPath As String, dPath As String
        Dim i As Long
    
    
        With Application
            .DisplayAlerts = False
            .ScreenUpdating = False
        End With
        
        sPath = "X:\03_IWP\IWP pdf\"
        dPath = "X:\03_IWP\Superintendent\"
    
    
        With CreateObject("Scripting.FileSystemObject")
            For i = 2 To Range("D" & Rows.Count).End(xlUp).Row
                If Not .FolderExists(dPath & Range("K" & i).Value) Then .CreateFolder (dPath & Range("K" & i).Value)
                .CopyFile sPath & Range("D" & i).Value & ".pdf", dPath & Range("K" & i).Value & "\"
            Next i
        End With
        
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    Thanks for the help! That was what I was looking for!

  5. #5
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are welcome.

    pls mark the thread as "solved" (see #4 in my forum signature) for future references to this thread.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •