0

I'm using this VBA syntax to open an input file from my active workbook:

Set wk = Workbooks.Open(datalink)

"datalink" here is a cell containing a link to the input file. In some cases, the data file doesn't exist so this syntax fails to open the link. How can I write a syntax that in those case, the macro still move on and ignore the error?

Thanks in advance. Excuse my very beginner question.

braX
  • 11,506
  • 5
  • 20
  • 33

1 Answers1

0

You can use the Dir function to see if it exists.

If Dir(datalink) = "" Then
  MsgBox datalink & " not found."
Else
  Set wk = Workbooks.Open(datalink)
End If
braX
  • 11,506
  • 5
  • 20
  • 33