Error handling help

G

Guest

Hi,
I have an auto_open macro that unprotects a file, calls a sub to import a
..csv file, then the auto_open macro protects the file again. This should
never happen, but if the .csv file is missing, naturally there's an error,
and in this case the file is left unprotected. I have some error handling
that calls the sub Protect_Sheets in the import sub in case the file is
missing. My problem is the auto_open macro calls the sub to import the file,
so I really need to end the auto_open macro after the file is protected
again. I can exit the import sub when there's an error, but am unsure how to
have error handling that actually ends the auto_open. I hope this makes
sense. Thanks for any ideas! This forum is the only way I really learn
anything.
 
G

Guest

Sub Auto_Open()
on Error goto EndMe

macro1

EndMe:
End Sub

Sub Macro1()

' no error handling or Resume statements


End sub

an error in Macro1 will immediately search up the calling change until it
finds an error handling routine. In this case, it goes to Auto_open and
ends.
 
G

Guest

an error in Macro1 will immediately search up the calling change until it

Change should be Chain

of course.
 
G

Guest

Tom, thanks for your response. That makes perfect sense, but I do have
another question. The code that unprotects the sheets runs prior to the sub
that imports the file. So the error is not found until after the sheets are
unprotected. The error is found and Auto_Open ends just like you said it
would, but it looks like the error is found too late if that makes any sense
to you. I've included the beginning part of Auto_Open. Pardon my lack of
experience (brains?).

Sub Auto_Open
On Error GoTo EndThis

'Call unprotect procedure
Unprotect_sheets

Worksheets("Export").Visible = xlSheetVisible
'Sets the width of the workbook's bottom tab area to make all tabs visible:
ActiveWindow.TabRatio = 0.667

'Code to import .csv; call ImportCSV procedure:
ImportCSV
 
G

Guest

Sub Auto_Open
On Error GoTo EndThis

'Call unprotect procedure
Unprotect_sheets

Worksheets("Export").Visible = xlSheetVisible
'Sets the width of the workbook's bottom tab area to make all tabs visible:
ActiveWindow.TabRatio = 0.667

'Code to import .csv; call ImportCSV procedure:
ImportCSV

' other code

Exit sub
EndThis:

' code that reprotects the sheets and whatever other actions you wish if an
error has occured.

end Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top