G
Guest
I have a general programming method. I'm fairly adept at using VBA to open
and manipulate Excel files from within an Access code module. I try to break
out the different logical steps of my process into different subs. A lot of
times, the different steps involve the same Excel workbook and/or worksheet.
I know that you can pass objects (like workbooks and worksheets) as
parameters from one sub to another. However, knowing that Microsoft often
allows you to do things that you shouldn't do, is this really a smart thing
to do? As far as I am aware, there are a couple of different methods to
accomplish what I do (the list below encompasses only the ones that I've
done):
1) Each sub has its own Excel.Application object (as well as Workbook and
Worksheet objects), which are created and destroyed each time the sub runs.
The file/path of the Excel document is passed to the sub as a parameter.
2) There is a module-level Excel.Application object, but each sub has its
own Workbook and Worksheet objects that get created and destroyed as the sub
runs. The file/path is passed as a parameter.
3) The Workbook/Worksheet objects themselves are passed as parameters.
Are there any distinct advantages or warnings regarding any of these
methods? Is it only a matter of personal preference? I'm at the point in my
career where I'm developing my own personal code-writing style, and I don't
want to adopt any bad habits.
Thanks.
and manipulate Excel files from within an Access code module. I try to break
out the different logical steps of my process into different subs. A lot of
times, the different steps involve the same Excel workbook and/or worksheet.
I know that you can pass objects (like workbooks and worksheets) as
parameters from one sub to another. However, knowing that Microsoft often
allows you to do things that you shouldn't do, is this really a smart thing
to do? As far as I am aware, there are a couple of different methods to
accomplish what I do (the list below encompasses only the ones that I've
done):
1) Each sub has its own Excel.Application object (as well as Workbook and
Worksheet objects), which are created and destroyed each time the sub runs.
The file/path of the Excel document is passed to the sub as a parameter.
2) There is a module-level Excel.Application object, but each sub has its
own Workbook and Worksheet objects that get created and destroyed as the sub
runs. The file/path is passed as a parameter.
3) The Workbook/Worksheet objects themselves are passed as parameters.
Are there any distinct advantages or warnings regarding any of these
methods? Is it only a matter of personal preference? I'm at the point in my
career where I'm developing my own personal code-writing style, and I don't
want to adopt any bad habits.
Thanks.