On Error Help
Hi Ken
and you have added the line
on error goto errhandler
--
Regards
Frank Kabel
Frankfurt, Germany
Ken wrote:
If it can not find the "F851.txt" file to open, it does
not go into the error trapping. I get:
Run-time error '1004':
'F851.txt' could not be found.....
-----Original Message-----
Hi
try
Sub Test()
Dim CountRows As Double
Dim I As Double
Dim Fund As String
Dim BFYS As String
'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))
'[....]
'Turn on warnings, auto recalc, etc.
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
exit sub
errhandler:
msgbox "Error occured"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
--
Regards
Frank Kabel
Frankfurt, Germany
Ken wrote:
We have a macro which we begin by turning off manual
recalculation, screen updating, etc. Then we import a text
file and run some code. At the end we turn the manual
recalculation, screen updating, etc. back on.
If the text file is not found or if the macro somehow
bombs, I want to have an error trapping routine that will
give the user an error message and that will also re-set
the manual recalculation. What code would I use to do this?
TIA.
.
|