Johnny C
Well-known Member
- Joined
- Nov 7, 2006
- Messages
- 1,069
- Office Version
- 365
- Platform
- Windows
I've been coding VBA since (ahem) 1993 or thereabouts. When the VBA interface came in there was always this pesky option of a class module, I never knew what they did because I'd never needed to use them (and I've done some hefty modules in my time, 1,000+ rows of VBA)
I recently thought, really I should know about them. So I learnt how to use them. I've used them in projects, simply because I wanted to understand them and get familiar with them. However they still seem over the top, I use them to do things I could have done in half the time without using classes. Plus there's always the thing that not many people seem to know or use them (I rarely see posts on here about them) and as a contractor my code always has to be as simple as possible for when someone else picks it up after I leave.
I appreciate that programmatically they're a more elegant way of doing something, turning values in cells into real data items. I'd expect to be expected to use them if I was doing an academic VBA course for example. But in the real world, Occam's razor applies, you need something doing as quickly as possible and as simply as possible.
The sort of stuff I've used them for tends to be where there's large tables of data that needs feeding into multiple sheets, make the sheetname a member of the class then all the columns of data as separate member types, pop them into a collection, then loop through the collection, pluck the data items for each class and populate the sheet with them. Something I would do in 15-30 mins normally, it probably takes twice as long with a class module approach.
Do people use them much? Is there a time when they really should be used? is there a reason they should be used (other than they're more elegant)?
I recently thought, really I should know about them. So I learnt how to use them. I've used them in projects, simply because I wanted to understand them and get familiar with them. However they still seem over the top, I use them to do things I could have done in half the time without using classes. Plus there's always the thing that not many people seem to know or use them (I rarely see posts on here about them) and as a contractor my code always has to be as simple as possible for when someone else picks it up after I leave.
I appreciate that programmatically they're a more elegant way of doing something, turning values in cells into real data items. I'd expect to be expected to use them if I was doing an academic VBA course for example. But in the real world, Occam's razor applies, you need something doing as quickly as possible and as simply as possible.
The sort of stuff I've used them for tends to be where there's large tables of data that needs feeding into multiple sheets, make the sheetname a member of the class then all the columns of data as separate member types, pop them into a collection, then loop through the collection, pluck the data items for each class and populate the sheet with them. Something I would do in 15-30 mins normally, it probably takes twice as long with a class module approach.
Do people use them much? Is there a time when they really should be used? is there a reason they should be used (other than they're more elegant)?
Last edited: