General discussion

Locked

Excel '97 VBA Error Handling - Need Hel

By hvanegas ·
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

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Excel '97 VBA Error Handling - Need Hel

by Slora In reply to Excel '97 VBA Error Handl ...

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

Collapse -

Excel '97 VBA Error Handling - Need Hel

by hvanegas In reply to Excel '97 VBA Error Handl ...
Collapse -

Excel '97 VBA Error Handling - Need Hel

by Oliver W. In reply to Excel '97 VBA Error Handl ...

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

Collapse -

Excel '97 VBA Error Handling - Need Hel

by hvanegas In reply to Excel '97 VBA Error Handl ...
Back to Software Forum
4 total posts (Page 1 of 1)  

Software Forums