Get full filepath

Mumba

New Member
Joined
May 3, 2018
Messages
14
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
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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