How do I open a file if I only know part of the file name?

excel, vba

Solution

`filename*esy` is already a "shell ready" wildcard & if thats alway the case you can simply;

const SOME_PATH as string = "c:\rootdir\"
...
Dim file As String
file = Dir$(SOME_PATH & "filename*esy" & ".*")

If (Len(file) > 0) Then
  MsgBox "found " & file
End If

Just call (or loop until empty) `file = Dir$()` to get the next match.

Problem

I need to open a file whose full filename I do not know. I know the file name is something like. ``` filename*esy ``` I know definitely that there's only one occurrence of this file in the given directory.

Original source