-1

The title might be confusing.

What I meant was, say I have the path and file saved under a variable.

sPath = "C:\Users\"

sFile = "*1234*.*"

sWorkbook = sPath & sFile

The idea is that the sFile should be as vague as possible to account for any file names which may come through this folder. However, now that I have the file name saved under the sWorkbook variable, I have no idea how to open it by referencing sWorkbook; e.g. workbooks.open("sWorkbook").

braX
  • 11,506
  • 5
  • 20
  • 33

1 Answers1

1

Use the Dir function to get the filename you want

sPath = "C:\Users\"
sWildcard = "*1234*.*"
sFile = Dir(sPath & sWildcard)
If sFile <> "" Then
  sWorkbook = sPath & sFile
  Workbooks.Open sWorkbook
Else
  Msgbox "File Not Found"
  ' Exit Sub '// optionally exit the subroutine so that it does not try to continue //
End If
braX
  • 11,506
  • 5
  • 20
  • 33