Home>

I'm sorry for rudimentary questions
I'm writing a program with standard modules and user forms
There are many procedures in one module, making it difficult to read (the number of procedures and subroutines has increased, making it difficult to know which one is being referenced or not used)
It was written that reading the book would make the program easier to read with the class module
When can I use a class module to make my program easier to read?
Should I use class modules for subroutines, ForNext, if, etc.

  • Answer # 1

      

    Is it better to use class modules for subroutines, ForNext, if, etc.

    Submodules, ForNext, if, etc. and class modules are of different dimensions, so even if you replace them with class modules, it will often be meaningless.

    Class modules are not easy to read, it depends on how you write and design.

    Excel and Access have various functions as standard, but they can be said to be one class. First, if you use it well, it will be simple and fast processing.

    As Excel and Access itself are highly functional, I don't think there are many processes that require class modules in VBA.

    Class modules may be effective when creating large, multi-functional ones, but it requires considerable skill.

      

    There are many procedures in one module, making it difficult to read (the number of procedures and subroutines has increased, making it difficult to know which one is being referenced or not used)

    First, the procedures are grouped into appropriate modules according to their roles. Divide the procedure into appropriate blocks that make the name of the procedure easy to understand and cheap. There are many ways to make it easier to read.

    Also, if you are calling a subroutine, you can jump to the subroutine code by placing the cursor there and right-clicking → Define (or SHuft + F2). Right click->move to the original position (or Ctrl + Shift + F2) to return to the caller.

    First of all, please take advantage of the above points to make an easy-to-read design.
    I think that even if you do not have the skills that can be done, even if you move on to the class module, it will be complicated and difficult to read.

    One thing that can be surely effective when using class modules is when there are many controls with similar roles and you want to share the event processing. The link below will be helpful.

    Combining multiple control events into a single procedure (ExcelVBA)-Personal computer college staff

    How to control Change events of Control objects in batch with ExcelVBA * Ateitexe