K
Ken
In the code below I have extracted all the miscellaneous
lines.
When I run the macro, if the text file that I am trying to
open (F851.txt) does not exist, the macro fails at
the "Workbooks.OpenText...." line. It does not go to
the "Errhandler."
Any ideas why?
----------------------------
Sub Payables()
'Turn off warnings, auto recalc, etc.
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
ChDir "C:\Downloads"
On Error GoTo Errhandler
Workbooks.OpenText Filename:="C:\Downloads\F851.txt",
Origin:=xlWindows, _
StartRow:=4, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2), Array(15 _
, 2), Array(25, 2), Array(37, 2), Array(53, 3),
Array(65, 1), Array(71, 1), Array(91, 1), _
Array(111, 1))
End_it:
'Turn on warnings, auto recalc, etc.
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Exit Sub
Errhandler:
MsgBox "Error occured"
Resume End_it
End Sub
lines.
When I run the macro, if the text file that I am trying to
open (F851.txt) does not exist, the macro fails at
the "Workbooks.OpenText...." line. It does not go to
the "Errhandler."
Any ideas why?
----------------------------
Sub Payables()
'Turn off warnings, auto recalc, etc.
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
ChDir "C:\Downloads"
On Error GoTo Errhandler
Workbooks.OpenText Filename:="C:\Downloads\F851.txt",
Origin:=xlWindows, _
StartRow:=4, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2), Array(15 _
, 2), Array(25, 2), Array(37, 2), Array(53, 3),
Array(65, 1), Array(71, 1), Array(91, 1), _
Array(111, 1))
End_it:
'Turn on warnings, auto recalc, etc.
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Exit Sub
Errhandler:
MsgBox "Error occured"
Resume End_it
End Sub