Hey all!
I'm looking for some help regarding the renaming of lots of PDF files. The PDFs are named like 042043341_38662557_0_96.pdf. The first part (042043341) is a unique reference number which is also situated in column D, the rest is not unique and is related to an order number.
I found this thread Rename all .pdf files in folder where the last page has the macro
I have tried to make this work with my data but I am having a struggle interpreting the code. The writer mentions the code will search in column A for a match of a part of the PDF name and if it is a match it will rename as columns A, B & C but I do not understand where in the code it relates to each of these fields.
I hope I have made some sense and appreciate any help you could offer.
Thanks!
I'm looking for some help regarding the renaming of lots of PDF files. The PDFs are named like 042043341_38662557_0_96.pdf. The first part (042043341) is a unique reference number which is also situated in column D, the rest is not unique and is related to an order number.
I found this thread Rename all .pdf files in folder where the last page has the macro
VBA Code:
Sub Shahzadt()
Dim z As Long, e As Long, g As Long, x As Long
Dim f As String
Cells(1, 1) = "=cell(""filename"")"
Cells(1, 2) = "=left(A1,find(""["",A1)-1)"
Cells(2, 8).Select
f = Dir(Cells(1, 2) & "*.pdf")
Do While Len(f) > 0
ActiveCell.Formula = f
ActiveCell.Offset(1, 0).Select
f = Dir()
Loop
z = Cells(Rows.Count, 8).End(xlUp).Row
x = Cells(Rows.Count, 1).End(xlUp).Row
For e = 2 To z
For g = 2 To x
If InStr(Cells(e, 8), Cells(g, 1)) > 0 Then
Name Cells(1, 2) & Cells(e, 1) As Cells(1, 2) & Cells(g, 1) & Cells(g, 2) & Cells(g, 3)
End If
Next g
Next e
MsgBox "Renaming is complete."
End Sub
I have tried to make this work with my data but I am having a struggle interpreting the code. The writer mentions the code will search in column A for a match of a part of the PDF name and if it is a match it will rename as columns A, B & C but I do not understand where in the code it relates to each of these fields.
I hope I have made some sense and appreciate any help you could offer.
Thanks!