#1
|
|||
|
|||
Organize Macro Codes for Reuse
I'm quite new to macro VBA. I want to reuse the codes I use in other documents.
How do you organize your code so they are reusable and easily identified ? Do you create modules, grouping procedures and function with similar functionality to a module ? Is there any naming convention for the procedure's, module's name ? What are your best practices ? Thanks |
#2
|
|||
|
|||
For me it's all in the name I give the individual macro a very descriptive name or a commented out line of text so searching is easy. I save all in modules and back up all in word docs.
|
#3
|
||||
|
||||
The simplest way is to have all your macros in the Normal template, so they're all automatically loaded into every doc. However, that can get cumbersome with a lot of macros.
Like Kilroy, I give each sub a very descriptive name, which can be long—clarity is the goal, eg: Sub ReplaceGiraffeWithGorilla() Quote:
When I have a lot of small routines which are part of a larger task, then the 'key macro' I mentioned will be one which calls each of the small ones—I give the key macros names which will sort at the top of the module display, in the order of execution. Example: Sub 1ReplaceAnimals () Call ReplaceGiraffeWithGorilla Call ReplaceRhinoWithHippo Call etc Sub 2ReplaceBirds () Call ReplaceVultureWithCondor Call ReplaceGooseWithDuck Call etc I have only a few macros in my Normal template, ie those I want to run every time I launch Word—eg AutoOpen & AutoNew to have the panels I want on screen from the start. In case you don't know, macros are stored in Word templates. If you want the macros in your file system, then you have to copy & paste from the Word VBA editor. Make sure to locate the templates in a place you backup—you lose 'em, your macros are gone. I keep most of my Office macros in separate templates, each of which is tailored to one of my main tasks. Each template contains only the macros relevant to that task. But that's just my preference. |
#4
|
||||
|
||||
Over the years I have created many add-ins, lots of which are available from my web site. I also use them to store macros that I use infrequently. To keep them readily available I created an add-in to handle them Load Word add-ins for the current session only which you may find useful.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
That's a good one. Thanks Kilroy.
|
#6
|
|||
|
|||
Thanks Lugh, gmayor. That really helps.
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
PPT 2016 refuses to copy/reuse slides from one pres. to another! | Pantucci | PowerPoint | 0 | 08-18-2017 06:14 AM |
Reuse slides deleting slide number and footer | PSSMargaret | PowerPoint | 0 | 05-12-2016 05:28 AM |
Auto-update field codes in Outlook Template - AutoOpen Macro not working | victoriasun | Outlook | 5 | 12-22-2015 01:54 AM |
Macro to read text file and organize data in excel | srinidhi.mv88 | Excel Programming | 5 | 05-19-2015 12:06 AM |
How do I keep graph sizing and location for reuse on a monthly basis | lynchbro | PowerPoint | 0 | 06-09-2014 08:06 AM |