• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

When to Use VBA

Although recorded macros can do just about anything in Word, it's often useful to be able to edit macros, or create new macros by writing your own VBA code. The following situations are just a few examples:

  • You have recorded a macro that works well, but now you would like to change the way it works without recording it again.

  • You want to prompt the user to input information, such as his name or a filename.

  • You want to display one of Word's dialogs so that a user can make selections from the dialog.

  • You want your macro to make logical decisions. For example, you can program a macro to function only if your current selection is in a table, or if the document is in Page Layout view.

  • You want to repeat an action many times. For example, a macro can apply header or footer formatting to each section in a long document.

  • You want to exchange data with other Office applications, or even perform actions using those applications.

  • A long, complex macro runs slowly, and you want to improve its performance.

  • You made a mistake while recording a macro, but you don't want to throw away the whole macro.

  • The VBA macro recorder doesn't always produce the most efficient VBA code. You can often improve the performance of your macros by editing the recorded code.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint