Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default 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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default 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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Workbooks.Opentext - oldskool '97 bradsalmon Excel Programming 4 June 9th 06 03:44 PM
Handling Errors and MessageBox Joel Mills Excel Programming 4 June 2nd 05 05:53 PM
Handling errors in formulas (how annoying are they!) anon90210 Excel Discussion (Misc queries) 1 January 17th 05 01:26 PM
Workbooks.OpenText Alistair Eberst Excel Programming 2 October 21st 03 12:50 PM
Handling Errors from Worksheet Functions Nigel[_4_] Excel Programming 1 October 7th 03 07:46 PM


All times are GMT +1. The time now is 04:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"