|
Option Explicit
'-----------------------------
Sub get_pdf_files()
'-----------------------------
Dim sFilter As String: sFilter = "D:\pdf\*.pdf"
Dim sFile As String
Dim oDic As Scripting.Dictionary: Set oDic = CreateObject("Scripting.dictionary")
Dim sKey As String
sFile = VBA.Dir(sFilter)
'----------------------
Do Until sFile = ""
'----------------------
sKey = Split(sFile, "_")(0)
'-----------------------
If oDic.Exists(sKey) Then
'-----------------------
oDic.Item(sKey) = oDic.Item(sKey) & "/" & Replace(sFile, ".pdf", "")
Else
oDic.Add sKey, Replace(sFile, ".pdf", "")
End If
sFile = Dir
Debug.Print sFile
'-----------------------
Loop
'-----------------------
Dim v As Variant
Dim rngX As Range
Set rngX = Range("E4")
Dim vResult As Variant
'-----------------------
For Each v In oDic.Keys
'-----------------------
rngX.Value = v
vResult = Split(oDic.Item(v), "/")
rngX.Offset(0, 1).Resize(1, UBound(vResult, 1) + 1).Value = vResult
Set rngX = rngX.Offset(1)
Next
End Sub
|
|