error handeling

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
2,126
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hello

i am trying to do call a macro if an error occours. Basically, the error is literally when the text file does not exist on a querytable, so when the .txt file does not exist i get an error, so i tried the below, but it does not bypass the error. it still displays the error message thet causes my long loop code to stop.

Code:
Sub LOAD_DAY()
On Error GoTo 0
    With Range("'day'!A1").QueryTable
        .Connection = "TEXT;C:\THERE OFF\DAYS\" & Range("'CHARTS'!U2").Text & ".txt"
        .TextFileColumnDataTypes = Array(1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2)
        .Refresh BackgroundQuery:=False
    End With
    Exit Sub
0:  Call RUN_APP
End Sub

anyone know what i can do.

thanks

dave
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
try
Code:
On Error Goto Xit
.
.
Xit:
Call RUN_APP
On Error goto 0 simply sets the error handler to the default
 
Upvote 0
hi fluff

ok thanks for that, will give it a try, i have also been working on a workaround to check if the file exists.

Code:
If Dir("C:\THERE OFF\DAYS\" & Range("'CHARTS'!U2").Text & ".txt") = "" Then MsgBox ("ISSUE"): Call RUN_APP

will let you know how i get on

thanks

dave
 
Upvote 0
yep, thanks fluff

it works just fine, many thanks.
my workaround also worked, but i think the error handler will be faster.

thanks again

dave
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top