Discussion Locked

Excel '97 VBA Error Handling - Need Hel

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I've coded a simple conversion utility for our corporation and I need a line at the beginning to have Excel completely EXIT if the first file doesn't exist (both files are coexistent). Please help

I know that in access the code might read
On Error Exit or something like that but not for Excel. The code is the following:' B A N K O F T O K Y O - M I T S U B I S H I
' L O S A N G E L E S B R A N C H
'
' Written by Hugo E. Vanegas
' Banking Assistant
' Corporate Banking Department No. 1
'
' ---------------------------------------------------------
' * This set of code converts both "g:\cmd-info" files: *
' * tickler.wk4
' * borr_trn.wk4
' *
' * to Excel '97
' * and then proceeds to delete both Lotus 1-2-3 files *
' *--------------------------------------------------------

If Error Exit
' Limits Scroll Area to window
For Each Sheet In Worksheets
Sheet.ScrollArea = "a1:k15"
Next Sheet

' This line goes to the next file if first file does no

4 replies

by slora

How about this, adapted from the Excel VBA help:

On Error Goto MyExit

... And at the end of your macro...

Sub MyExit
Exit Sub
End Sub

by oliver w.

Usually VBA functions and subs should look like this
Public Function MyFunction()
On Error GoTo MyFunction_Error
'Here goes the Code

MyFunction_Exit:
'Here you can put final code,
' free variables,...
Exit Function 'Important, otherwise the
'function will continue to
'the error part.

MyFunction_Error:
'Put your Error Handling here
MsgBox Err & ":" & Err.Description
Resume MyFunction_Exit 'Jump the the 'Exit Block
End Function

hope that helps
Oliver

This discussion is closed to new replies.