More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

Login

login
password
Remember me

You will need to register and log in if you want to download the source code for the Microsoft Outlook Programming book. The forums and code sharing areas are open to both registered and non-registered visitors.

share code 02-Sep-2010 22:27

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

 

Code level: beginner    Code area: Basic Outlook Printer Friendly Version
Title: Start Outlook from other program
Description: This code checks for a running instance of Outlook and, if found, returns that. If Outlook isn't running, it starts Outlook with a specific optional profile name. The one thing I haven't figured out is how to suppress the profile dialog completely.
Date: 03-Apr-2003  01:30
Code level: beginner
Code area: Basic Outlook
Posted by: Sue Mosher
Body:
All 20comments
Page [ 1 2 Next >>  
  23-Apr-2003  10:32   
Sue,

Hi. I'm trying to do the exact same thing with word from Access VB. However the line

Set wdApp = GetObject(, "Word.Application")

returns Run Time error '429' - ActiveX component can't create object.

Any ideas? Would greatly appreciate it if you could help. Thanks, Matt
  23-Apr-2003  11:45   
Sue, I found the answer on the MSND site - VBA lang. ref for GetObject. And now looking at your code, I see the all important "On error resume next". Why do we sometimes miss these important details? :) Cheers, Matt
  30-Apr-2003  06:47   
Good question, Matthew. That's actually one I pondered while I was writing the book: A lot of peoople new to programming seem to think that you always need to avoid triggering runtime errors. It's hard to get used to the idea that runtime errors are actually part of the game and that statements like "On Error Resume Next" are essential to getting the program to do what you intend. This is especially true for CDO programming, but even Outlook has its spots where you must anticipate a possible error -- as when you use Namespace.PickFolder to display the folder list, but the user cancels without picking a folder.
  04-May-2003  14:46   
Hi Sue,

What would be the equiv. of the GetObject in C#?

ErikAnthony
  16-Aug-2005  07:56   
For a sample that shows how to open Outlook with a shell command so that the user's choice of initial folder is displayed, see http://www.outlookcode.com/threads.aspx?forumid=2&messageid=13440
  07-Mar-2007  11:10   
Optional and typed data declarations are not suppported in VBScript, so to adapt it for use there, you'd use this to return an Outlook.Application object:

Function OpenOL(ProfileName) ' As Outlook.Application
    Dim objOL ' As Outlook.Application
    On Error Resume Next
    Set objOL = GetObject(, "Outlook.Application")
    If objOL Is Nothing Then
        Set objOL = CreateObject("Outlook.Application")
        objOL.Session.Logon ProfileName, "", False, True
    End If
    Set OpenOL = objOL
    Set objOL = Nothing
End Function
  18-Sep-2007  07:19   
Hi

The problem I have (Outlook 2003 in an Exchange Environment): As soon as the code runs CreateObject("Outlook.Application"), it triggers the profiles-Dialog. Only after that the code runs the next line objOL.Session.Logon ... etc.

How to prevent this very first Profile-Dialogue Trigger.

Thx. SlamJam
  18-Sep-2007  09:12   
SlamJam, I can't say that I've ever seen Outlook operate like that. What kind of application are you creating that you need to use CreateObject?
  18-Sep-2007  09:41   
I'm working out of MS-Access, getting the Outlook Object with this code:

Function StartOutlook(Optional ysnShow As Boolean) As Outlook.Application

Dim OApp As Object
  
On Error Resume Next


' Try to get open Outlook
Set OApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
  Err.Clear
  
  ' Initialise OL, if not yet an instance
  Set OApp = CreateObject("Outlook.Application")
  gLng_OutlErg = 0
Else
  gLng_OutlErg = 1
End If

' Activate Outlook
If ysnShow = True Then OApp.Activate = True
Set StartOutlook = OApp
Set OApp = Nothing

End Function
  18-Sep-2007  11:10   
As I said, I don't recall seeing that behavior and don't know why it might occur. You ought to declare oApp as Outlook.Application, but that shouldn't make any difference. If you're getting a profile dialog, then you could just go ahead and choose the profile without any need for a Namespace.Logon statement.

Also note that there is no Activate method for the Outlook.Application object.
Page [ 1 2 Next >>  
Post your comment



name        email