Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50049

Find File with partial filename and get path of folder

$
0
0
Hey there ppl,

again I am stuck and don't know what to do....


I have cells with names of folders, there are two types of names 12345678 and AB987453.
The Directory where I am trying to search the files, is fixed, but it has subfolders.
Cell A1 has the name AB987453 (or sometimes 54387135 ), the directory "C:/xxx/aaa/AB987453_54387135/AB987453_54387135.pdf" and I want to get the path "C:/xxx/aaa/AB987453_54387135/".

I tried the following code, but it won't do anything....
Hope you guys can help me!

Code:

Public Sub Find_File()
   
   
    Dim Temp_File_Name As String
    Dim File_Name As String
    Dim FileName As String
       
    FileName = Cells(11, 2).Value
    Temp_File_Name = "Z:\Planung\China-Team-EA211\Projekt_EA211_Loutang_II\09_Produktdaten_TBP_ES-Listen\Äko\" & "*" & FileName & "*" & ".pdf"
   
    File_Name = Dir(Temp_File_Name, vbNormal)
   
    While File_Name <> ""
       
        MsgBox File_Name
        File_Name = Dir
       
    Wend
   
End Sub


Viewing all articles
Browse latest Browse all 50049

Trending Articles