Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default 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.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error handling Sarah at DaVita Excel Programming 2 August 18th 07 06:14 AM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM
Error Handling bw Excel Programming 3 June 20th 04 06:43 PM
Error Handling James Agostinho Excel Programming 1 January 30th 04 06:40 AM


All times are GMT +1. The time now is 08:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"