Handling Errors with Workbooks.OpenText
I've got this line of code:
Workbooks.OpenText FileName:=sFilePath & ".xls", _ DataType:=xlDelimited, Tab:=True The file is opened using the path and filename entered by the user into a form. How can I handle errors so that if the file/path is invalid or the file doesn't exist, it gives an error message rather than falling over? Thanks. |
Handling Errors with Workbooks.OpenText
Hello David
Use an Error Handler eg: Sub tester() On Error GoTo tester_Error Workbooks.OpenText Filename:=SFilepath & ".xls", _ DataType:=xlDelimited, Tab:=True On Error GoTo 0 Exit Sub tester_Error: MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure tester of Module Module1" End Sub HTH Cordially Pascal "David" a écrit dans le message de news: ... I've got this line of code: Workbooks.OpenText FileName:=sFilePath & ".xls", _ DataType:=xlDelimited, Tab:=True The file is opened using the path and filename entered by the user into a form. How can I handle errors so that if the file/path is invalid or the file doesn't exist, it gives an error message rather than falling over? Thanks. |
Handling Errors with Workbooks.OpenText
On Oct 16, 9:10 am, "papou"
wrote: Hello David Use an Error Handler eg: Sub tester() On Error GoTo tester_Error Workbooks.OpenText Filename:=SFilepath & ".xls", _ DataType:=xlDelimited, Tab:=True On Error GoTo 0 Exit Sub tester_Error: MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure tester of Module Module1" End Sub HTH Cordially Pascal "David" a écrit dans le message de news: . com... I've got this line of code: Workbooks.OpenText FileName:=sFilePath & ".xls", _ DataType:=xlDelimited, Tab:=True The file is opened using the path and filename entered by the user into a form. How can I handle errors so that if the file/path is invalid or the file doesn't exist, it gives an error message rather than falling over? Thanks.- Hide quoted text - - Show quoted text - Thanks Pascal, that was exactly what I wanted. |
All times are GMT +1. The time now is 04:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com