Get full filepath

Mumba

New Member
Joined
May 3, 2018
Messages
13
Hi Guys

Can anyone please help me.
I am trying to add to the macro below, but i can't seem to find the right method.
I am searching a folder for picture files. My issue however is, that am only able to search for files using a "*" as i do not know the full file name, only a article number.
When the search finds a match, i need the macro to return the full name of the path including whatever the "*" represents

Code:
Sub Picpath()

    Dim Picpath As String
    fpath = "S:\Applications\Uniflow\Productdrawings\Picture Iproduct\"
    NoPicPath = "S:\Applications\Uniflow\Productdrawings\Picture Iproduct\photo_not_available.jpg"
    
    For I = 12 To lr
            Picpath = fpath & wsmaster.Cells(I, ColItem).Value
            
            If Dir(Picpath & "*.jpg") <> "" Then
                wsmaster.Cells(I, ColPic) = Picpath & ".jpg"
            ElseIf Dir(Picpath & "*.png") <> "" Then
                wsmaster.Cells(I, ColPic) = Picpath & ".png"
            Else
                wsmaster.Cells(I, ColPic) = NoPicPath
            End If
    Next
End Sub
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,357
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
You need to store the result of Dir

Code:
Dim FileName as string
            filename = Dir(Picpath & "*.jpg")
            if filename <> "" Then
                wsmaster.Cells(I, ColPic) = Picpath & filename
            Else
filename = Dir(Picpath & "*.png")
If filename <> "" Then
                wsmaster.Cells(I, ColPic) = Picpath & filename
            Else
                wsmaster.Cells(I, ColPic) = NoPicPath
            End If
        End If
 

Forum statistics

Threads
1,082,380
Messages
5,365,124
Members
400,824
Latest member
Themilkybarkid

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top