Outlook - VBA

Creating Your Own Constants For Functions

| | | | | |

Introduction:
One of the items that is very useful in code is the use of constants. These items are simply text masks that translate to numbers, making it easier for us to remember how to interact with the code.

For example, if you put "? vbOkOnly" in the immediate window, you'll see that it resolves to 0. Likewise, "? vbYes" resolves to 6. It's much easier to remember the words than the numbers, which is why Enumerations (or Enums) exist.

Creating your own Constants
The good news is that beginning with Excel 2000, we have been given the ability to program our own Enumerations to help in our coding!

Using Help in Your Applications

| | | | | |

Introduction:
One of the biggest parts lacking in user constructed solutions is documentation in the form of help files. As coders, we usually find it easier to build the application than explain to someone how to use it properly. After all, what we write in code is rarely read by others, and most novices think it's gibberish anyway. Actually explaining what you do in plain english (or whatever language you use) can be quite difficult. Ironically, it is this very fact that tells us why help files are important... write it down once, nicely, and you should never have to explain it again.

Controlling When Application Properties Are Toggled and Controlling Events

| | | | | |

Introduction:
This article actually covers two topics. The first is on controlling when application properties are toggled, and the second shows how to adapt that methodology into a superior method to manage events and prevent recursive calls. The first example set is purely based on Excel, but the methodology can be easily adpated to other applications. The second example is based on an userform and is not application specific.

Controlling When Application Properties Are Toggled:
I frequently have routines in Excel where I turn off ScreenUpdating, both to stop the flashing and speed up the code. The issue that I ran into is that I like to separate my code into reusable chunks. I didn't want to turn ScreenUpdating off/on in each routine, since the screen would then flash between routines, which ended up forcing me to write a wrapper for every function, in case I wanted to run in on it's own. This method takes care of that problem. I can write the ScreenUpdate into each chunk, and it will turn ScreenUpdates back on only if it was run standalone. This allows me to call as many routines as I want, nest them and more.

Send Email Using ClickYes

Introduction
Every now and then, you may need to send an email from another application through Outlook. If you've ever thought about automating this process using Outlook 2000, Outlook 2002 or Outlook 2003, then no doubt you've run into the dreaded Outlook security prompt upon trying to send:

This article covers using Express ClickYes from ContextMagic, to deal with the issue. It does not completely avoid the Outlook security prompt, but it does dismiss it after a short period of time. One of the things that makes Express ClickYes more attractive than competitive solutions is that Express ClickYes is licensed to use for free in both personal and commercial activities.

Examples Of Using Late Binding To Connect To Other Applications

| | | | |

Introduction:

This article contains examples of using late binding to attach to the current instance or create a new instance of a variety of applications. It contains examples for creating the following from another application:

  1. Access
  2. Excel
  3. Powerpoint
  4. Publisher
  5. Word

Please note that you can copy these code examples into any application that supports VBA, but the called application must be installed on your system for it to work. Just copy them into a standard module and run them. (No references need to be set in the Visual Basic Editor in order to make this code work.)

Connecting To/Creating A New Application Instance Via Late Binding

| | | | |

Introduction:

There are actually two different ways to accomplish this task, depending on exactly what you want to do. You can:

  1. Connect to an existing application (uses the GetObject method)
  2. Create a new application with no document loaded (uses the CreateObject method)

Please note that while all of this code was written to control Microsoft Word from Excel, you can use it in any other VBA enabled application, and you can also use it to control any other VBA enabled application, simply by changing "Word" to Excel, Powerpoint, Access, etc... in the examples below. For ready built examples, click here!

Syndicate content