Ryan Hare
Ryan Hare

Reputation: 31

Using wildcard * to complete file name

I'm putting together a VBA code to attach a document to an email, but I only have the first part of the document name to be attached. I've tried using "*" at the end so that it finds the document with what I have, but that's not working. Could anyone help? This is what I have:

If EmailType = "KiteWorks" Then

    .Attachments.Add ("File Path (redacted)\Results Enquiry " & AppLog.Cells(BatchRow, 2).Value & " " & BatchNumber & "*")

End If

(this section is within a with)

I'm testing with a document that is called "Result Enquiry 2 2 [Art].pdf" but I keep getting an error that the name or directory is not valid. I believe the issue is with the wildcard "*" that I hoped would fill in for the "[Art].pdf"

Thank you very much in advance.

Upvotes: 0

Views: 835

Answers (1)

Ryan Hare
Ryan Hare

Reputation: 31

Thank you BigBen for making me realise how silly I was being...

Updated my code to:

If EmailType = "KiteWorks" Then

    FilePath = "Path Redacted" & "\Results Enquiry " & AppLog.Cells(BatchRow, 2).Value & " " & BatchNumber & "*"
    FileExists = Dir(FilePath)

    If FileExists = "" Then
    
        MsgBox "Could not find PDF of script in scanned folder."
        
    Else

        .Attachments.Add ("Path Redacted" & FileExists)

    End If
    
End If

Upvotes: 1

Related Questions