open file validation

A

Alberto Ast

how do I validate while trying to open a file with macros so it will not fail
if file does not exist?
 
J

Jacob Skaria

Try the below..


Sub Macro()

Dim strFile As String
Dim wb As Workbook

strFile = "c:\1.xls"
If Dir(strFile, vbNormal) = "" Then
MsgBox strFile & vbLf & "File not found": Exit Sub
End If
Set wb = Workbooks.Open(strFile)
End Sub

If this post helps click Yes
 
A

Alberto Ast

thanks Jacob, I'll try it...
thanks for your support on several questions today.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top