Renaming PDF files based on Excel column Data

Halley yenn

New Member
Joined
Mar 17, 2021
Messages
32
Office Version
  1. 365
Platform
  1. Windows
Hi ,

I have a folder(D:/Test/) with 5 Pdf files with names as mentioned below
1) FY21 Employee Basic TET
2)FY21 Employee Basic BSD
3)FY21 Employee Basic GERT
4)FY21 Employee Basic KPIOT
5)FY21 Employee Basic SARD(common)
These Files need to renamed multiple times with the data present in an excel sheet as per Column C where the letter category is mentioned if an employee come under say TET then the pdf file need to renamed as EMPNAME_EMPID_FY21 Employee Basic TET.PDF and this should be done to 5K employees , employee may fall under any of these 4 categories and the last file is common file which need to be renamed like EMPNAME_EMPID_FY21 Employee Basic SARD.PDF for all the employees.
The data in the column is like
TET
BSD
GERT
KPIOT

Kindly help me resolve this as this need to be done bi-weekly.
Thanks in advance.

Halley
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Can't really fully test this, but:
MrExcelPlayground.xlsm
ABC
1Emp NameEmp IDGroup
2Emp1a1TET
3Emp2a2TET
4Emp3a3BSD
5Emp4a4GERT
6Emp5a5KPIOT
7Emp6a6TET
8Emp7a7BSD
9Emp8a8GERT
10Emp9a9TET
11Emp10a10BSD
12Emp11a11TET
13Emp12a12BSD
14Emp13a13GERT
15Emp14a14KPIOT
16Emp15a15TET
17Emp16a16BSD
18Emp17a17GERT
19Emp18a18KPIOT
20Emp19a19TET
21Emp20a20BSD
22Emp21a21TET
23Emp22a22BSD
24Emp23a23GERT
25Emp24a24KPIOT
Sheet38


code:
VBA Code:
Sub pdfcopier()
Dim path1 As String
Dim path2 As String
Dim filename1 As String
Dim filename2 As String
Dim SARD1 As String
Dim SARD2 As String

path1 = "D:\TEST\"
path2 = "D:\TEST\SomeOtherFolder\"
SARD1 = "FY21 Employee Basic SARD"

For t = 2 To 5000
    filename1 = "FY21 Employee Basic " & Cells(t, 3) & ".pdf"
    filename2 = Cells(t, 1) & "_" & Cells(t, 2) & "_FY21 Employee Basic " & Cells(t, 3) & ".pdf"
    SARD2 = Cells(t, 1) & "_" & Cells(t, 2) & "_FY21 Employee Basic SARD"

    FileCopy path1 & filename1, path2 & filename2
    FileCopy path1 & SARD1, path2 & SARD2
Next t
End Sub
 
Upvote 0
Can't really fully test this, but:
MrExcelPlayground.xlsm
ABC
1Emp NameEmp IDGroup
2Emp1a1TET
3Emp2a2TET
4Emp3a3BSD
5Emp4a4GERT
6Emp5a5KPIOT
7Emp6a6TET
8Emp7a7BSD
9Emp8a8GERT
10Emp9a9TET
11Emp10a10BSD
12Emp11a11TET
13Emp12a12BSD
14Emp13a13GERT
15Emp14a14KPIOT
16Emp15a15TET
17Emp16a16BSD
18Emp17a17GERT
19Emp18a18KPIOT
20Emp19a19TET
21Emp20a20BSD
22Emp21a21TET
23Emp22a22BSD
24Emp23a23GERT
25Emp24a24KPIOT
Sheet38


code:
VBA Code:
Sub pdfcopier()
Dim path1 As String
Dim path2 As String
Dim filename1 As String
Dim filename2 As String
Dim SARD1 As String
Dim SARD2 As String

path1 = "D:\TEST\"
path2 = "D:\TEST\SomeOtherFolder\"
SARD1 = "FY21 Employee Basic SARD"

For t = 2 To 5000
    filename1 = "FY21 Employee Basic " & Cells(t, 3) & ".pdf"
    filename2 = Cells(t, 1) & "_" & Cells(t, 2) & "_FY21 Employee Basic " & Cells(t, 3) & ".pdf"
    SARD2 = Cells(t, 1) & "_" & Cells(t, 2) & "_FY21 Employee Basic SARD"

    FileCopy path1 & filename1, path2 & filename2
    FileCopy path1 & SARD1, path2 & SARD2
Next t
End Sub
Hi,
Thanks for the prompt reply and sorry for late response I couldn't check this as I was out of station these days.
Just checked the code and it ran well, but I am getting errors where for some employees it says "No Letter"( Iam reffering to column C/3 from the worksheet you provided) where the code is stopping and one more thing there is one more column say column D where for some employees it shows date(say 03-04-2021) and I need to ignore them.
 
Upvote 0
Hi,
Thanks for the prompt reply and sorry for late response I couldn't check this as I was out of station these days.
Just checked the code and it ran well, but I am getting errors where for some employees it says "No Letter"( Iam reffering to column C/3 from the worksheet you provided) where the code is stopping and one more thing there is one more column say column D where for some employees it shows date(say 03-04-2021) and I need to ignore them.
please find the image for reference. Need to ignore both "No letter"(column C) and "withDate"(column D)
 

Attachments

  • WhatsApp Image 2021-04-06 at 9.54.20 PM.jpeg
    WhatsApp Image 2021-04-06 at 9.54.20 PM.jpeg
    138.4 KB · Views: 41
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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