ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   open file validation (https://www.excelbanter.com/excel-programming/435398-open-file-validation.html)

Alberto Ast[_2_]

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

Jacob Skaria

open file validation
 
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
---------------
Jacob Skaria


"Alberto Ast" wrote:

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


Alberto Ast[_2_]

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

"Jacob Skaria" wrote:

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
---------------
Jacob Skaria


"Alberto Ast" wrote:

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



All times are GMT +1. The time now is 12:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com