ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error handling help (https://www.excelbanter.com/excel-programming/398250-error-handling-help.html)

cottage6

Error handling help
 
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.

Tom Ogilvy

Error handling help
 
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.

--
Regards,
Tom Ogilvy


"cottage6" wrote:

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.


Tom Ogilvy

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

Change should be Chain

of course.

--
regards,
Tom Ogilvy


"Tom Ogilvy" wrote:

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.

--
Regards,
Tom Ogilvy


"cottage6" wrote:

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.


cottage6

Error handling help
 
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 procedu
ImportCSV


"Tom Ogilvy" wrote:

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


Change should be Chain

of course.

--
regards,
Tom Ogilvy


"Tom Ogilvy" wrote:

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.

--
Regards,
Tom Ogilvy


"cottage6" wrote:

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.


Tom Ogilvy

Error handling help
 
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 procedu
ImportCSV

' other code

Exit sub
EndThis:

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

end Sub


"cottage6" wrote:

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 procedu
ImportCSV


"Tom Ogilvy" wrote:

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


Change should be Chain

of course.

--
regards,
Tom Ogilvy


"Tom Ogilvy" wrote:

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.

--
Regards,
Tom Ogilvy


"cottage6" wrote:

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.


cottage6

Error handling help
 
Of course! Thanks for your help and patience; I'm all set.

"Tom Ogilvy" wrote:

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 procedu
ImportCSV

' other code

Exit sub
EndThis:

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

end Sub


"cottage6" wrote:

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 procedu
ImportCSV


"Tom Ogilvy" wrote:

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

Change should be Chain

of course.

--
regards,
Tom Ogilvy


"Tom Ogilvy" wrote:

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.

--
Regards,
Tom Ogilvy


"cottage6" wrote:

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.



All times are GMT +1. The time now is 05:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com