Excel VBA Dir() command help

:hang:

I am trying to check if a .pdf exists before attaching it to an e-mail.

The location and name of the .pdf will be different each time so I can’t hard code it.

THIS WORKS

If [COLOR=blue]**Dir(C:\Some\File\Path\my.pdf)** [/COLOR]<> "" Then
 
MsgBox "FILE FOUND"

Else

MsgBox "## error - File does not exist ##" 

End If

THIS WORKS


**[COLOR=red]myfile = "C:\Some\File\Path\my.pdf"[/COLOR]**

If **[COLOR=blue]Dir(myfile)[/COLOR]** <> "" Then
 
MsgBox "FILE FOUND"

Else

MsgBox "## error - File does not exist ##" 

End If

But as I can’t hard code it, I need to pass the Path and file Name to it.

THIS DOESN’T WORK

Path = ActiveWorkbook.Path
Name = ActiveCell.Value

**[COLOR=red]myfile = Path & Name[/COLOR]**

If[COLOR=blue] **Dir(myfile)**[/COLOR] <> "" Then
  
MsgBox "FILE FOUND"
 
Else
 
MsgBox "## error - File does not exist ##" 
 
 End If

In the version above that doesn’t work.
Stepping through the code shows that [COLOR=blue]Dir(myfile)[/COLOR] has the same value as the one that does work.

Dim myfile As String has no effect.

Given that[COLOR=blue] Dir(myfile)[/COLOR] has the exact same value in the one that doesn’t work and the one that does work.
I don’t know why it isn’t working.

Vulcan.