Consulting

Results 1 to 4 of 4

Thread: Outlook Instancing - or not?

  1. #1
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location

    Outlook Instancing - or not?

    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:
    [VBA]Set appOL = CreateObject("Outlook.Application")[/VBA]
    used within Outlook itself, instead of the simpler
    [VBA]Set appOL = Application[/VBA]
    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?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  2. #2
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    About the code with CreateObject within Outlook itself, it seems to me just like copy & paste from VB or another Office-Application.

  3. #3
    Knowledge Base Approver VBAX Expert brettdj's Avatar
    Joined
    May 2004
    Location
    Melbourne
    Posts
    649
    Location
    Tony - you are not alone

    I bought one of the better Outlook VBA books and routinely it starts code from within Outlook with
    [vba]
    CreateObject("Outlook.Application")
    [/vba]

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

    Cheers

    Dave

  4. #4
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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).
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •