In VBA should code that modifies document be avoided in a class module

Viewed 409

I am starting to use Classes in VBA and appreciate some of the fantastic information that is already available on SO.

As far as I can tell, what seems to be lacking is an explanation of what the code in a class should or, as I suspect, should NOT do. For example:

Lets say I have a document and wish to insert / modify a table. In this example I'd like to:

  • check if the table exists
  • if table does not exist:
    • add the table at a specific location
    • add information to the table (i.e. add rows)
  • if table does exist
    • add / delete information to /from the table
    • sort the table according to some criteria

With respect to 'sorting' I imagine that a class module would be well suited to determining the order that information should be put into a table based on some criteria.

But ideally:

  • Should the class module (or a 2nd class module) be used to check and edit the document?

OR

  • Would checking and/or editing be best done using a regular module?

Or doesn't it matter? If there is a preferred way then what are the advantages / disadvantages of each approach?

1 Answers
Related