Chaoxite
New Member
- Joined
- Dec 30, 2024
- Messages
- 3
- Office Version
- Prefer Not To Say
- Platform
- Windows
Hello everyone, this is my first post
So, for some years I have had a macro-enabled workbook that I also use as a library file of common procedures I can use. In my last job, I created several Excel templates that were used for reporting. Each template was a unique report and contained some VBA for its own needs but each used my library file for general/common code, such as connecting to a SQL server database and using ADO to download data etc. I have a general rule that VBA that is very generic goes in the library file and VBA that is only relevant within the file itself, goes in that file.
Anyway, I've been using standard modules for the most part with a couple of class modules that extend the functionality of certain MS Access controls but that's another story. I've been thinking of late to switch everything to class modules and wanted to get an idea if people thought this would do more harm than good. I've seen things on other posts that class modules are slower than standard but after running the same test several times on both a standard module and class module, they both performed at 15-16 seconds. I know class modules have to be instantiated but even standard modules have to be loaded into memory to at some point. I'm also aware of the VB_PredeclaredId = True means a class is automatically instantiated without the need to create it explicitly.
There are three main reasons for wanting to switch to class modules. First, any VBA inside a given class will represent a specific theme (such as Excel functions, Access, File System, ADO, DAO, etc.). This is currently how they are setup in their standard modules. If they are in classes though, this would prevent unintentional dependencies from forming i.e. the VBA in each class will not have to reference VBA in another module except for the common error handling module.
The second reason is more along the lines of being organised (this is a refactoring exercise too), since I have quite a lot of functions beginning with "Get" or "Create" so instead of calling CompareExcelRangeRows it would be Excel.Range.CompareRows or something like that. With Excel and Range being classes if there are enough functions in those categories to warrant two classes and if not, something like Excel.CompareRangeRows.
And thirdly, if I decide to switch a class library DLL via VB.net, then everything needs to be in classes anyway.
I would appreciate any thoughts on this matter although it is more of a "preference" or "what works best" type of question.
Thanks all.
So, for some years I have had a macro-enabled workbook that I also use as a library file of common procedures I can use. In my last job, I created several Excel templates that were used for reporting. Each template was a unique report and contained some VBA for its own needs but each used my library file for general/common code, such as connecting to a SQL server database and using ADO to download data etc. I have a general rule that VBA that is very generic goes in the library file and VBA that is only relevant within the file itself, goes in that file.
Anyway, I've been using standard modules for the most part with a couple of class modules that extend the functionality of certain MS Access controls but that's another story. I've been thinking of late to switch everything to class modules and wanted to get an idea if people thought this would do more harm than good. I've seen things on other posts that class modules are slower than standard but after running the same test several times on both a standard module and class module, they both performed at 15-16 seconds. I know class modules have to be instantiated but even standard modules have to be loaded into memory to at some point. I'm also aware of the VB_PredeclaredId = True means a class is automatically instantiated without the need to create it explicitly.
There are three main reasons for wanting to switch to class modules. First, any VBA inside a given class will represent a specific theme (such as Excel functions, Access, File System, ADO, DAO, etc.). This is currently how they are setup in their standard modules. If they are in classes though, this would prevent unintentional dependencies from forming i.e. the VBA in each class will not have to reference VBA in another module except for the common error handling module.
The second reason is more along the lines of being organised (this is a refactoring exercise too), since I have quite a lot of functions beginning with "Get" or "Create" so instead of calling CompareExcelRangeRows it would be Excel.Range.CompareRows or something like that. With Excel and Range being classes if there are enough functions in those categories to warrant two classes and if not, something like Excel.CompareRangeRows.
And thirdly, if I decide to switch a class library DLL via VB.net, then everything needs to be in classes anyway.
I would appreciate any thoughts on this matter although it is more of a "preference" or "what works best" type of question.
Thanks all.