View Full Version : Outlook Instancing - or not?

03-08-2005, 01:52 AM
If I'm working in Excel and want to use automation to access a Word Document, I can check if Word is already running and, if it is, use an existing instance of it, or I can create a new instance. There is no problem running multiple instances and I may or may not want to do so.

If, instead, I want to access Outlook Mail, I don't have the same options; there can only be a single instance of Outlook running at any one time. If I try and create a new instance I will be connected to the existing one if there is one.

I see a lot of code posted, here and on other boards, that, whenever access to Outlook is required (even to a required existing instance), codes to create a new instance - either using CreateObject or Dim ... New ... This seems like sloppy coding to me, relying on the system to understand what you mean even though you don't say what it is.

Even more confusing to me, I see:
Set appOL = CreateObject("Outlook.Application")
used within Outlook itself, instead of the simpler
Set appOL = Application
or just simple use of the Application object.

Is there something I'm not understanding - and/or are there any implications of this - or is there a lot of poor code out there?

03-08-2005, 02:14 AM
About the code with CreateObject within Outlook itself, it seems to me just like copy & paste from VB or another Office-Application.

03-08-2005, 02:45 AM
Tony - you are not alone

I bought one of the better Outlook VBA books and routinely it starts code from within Outlook with


I posed this question in an Outlook forum and didn't get much of an answer



03-08-2005, 02:51 PM
Thanks, both,

You, at least implicitly, seem to agree with me that it's wrong.

It seems to me to be the kind of code a beginner would write. With any other app, they'd probably stumble over the implications; with Outlook they get away with it.

I don't have, and haven't read, any books on Office or VBA (except Anne's :)) so I don't know what they're like in general but I'm a bit surprised to hear you say that a 'good' book is propagating 'bad' code. I'll have to write a better book (just got to learn Outlook first).