I am developing my 1st full fledged Excel program and have a question on proper coding etiquette for sub-procedure calls.
For example. I have a module that opens a workbook, formats it and then saves it. I have broken it down into 3 sub-procedures with appropriate code for each:
Sub Open ()
Sub Format ()
Sub Save ()
Question 1: Is it better to have one main procedure that calls the 3:
Sub Main ()
Call Open
Call Format
Call Save
End Sub
OR
Have each sub Procedure call the next.
Question 2:
The 1st option appears easier to follow HOWEVER, I find that if there is an error in, say Sub Open () (e.g. file does not exist) and I end the Open()procedure with an error handler in Open (), then Sub Main will still try to continue with Format()and Save(). If I use Option 1, how do I stop Main() entirely if there is an error in any of the called procedures.
An earlier posting had suggested switching the sub procedures to Functions to test completion of each step. I am still experimenting with how to do this but wonder if there is another alternative.
Any advice greatly appreciated.
Thanks
jdttek
For example. I have a module that opens a workbook, formats it and then saves it. I have broken it down into 3 sub-procedures with appropriate code for each:
Sub Open ()
Sub Format ()
Sub Save ()
Question 1: Is it better to have one main procedure that calls the 3:
Sub Main ()
Call Open
Call Format
Call Save
End Sub
OR
Have each sub Procedure call the next.
Question 2:
The 1st option appears easier to follow HOWEVER, I find that if there is an error in, say Sub Open () (e.g. file does not exist) and I end the Open()procedure with an error handler in Open (), then Sub Main will still try to continue with Format()and Save(). If I use Option 1, how do I stop Main() entirely if there is an error in any of the called procedures.
An earlier posting had suggested switching the sub procedures to Functions to test completion of each step. I am still experimenting with how to do this but wonder if there is another alternative.
Any advice greatly appreciated.
Thanks
jdttek