Solved

How do I create Outlook email using VB .NET if Outlook is already open?

Posted on 2011-03-13
8
3,645 Views
Last Modified: 2012-05-11
I would like to create an email in Outlook from my VB .net application. My code works fine if Outlook is closed but throws an error if Outlook is already open.

Imports Outlook = Microsoft.Office.Interop.Outlook

Dim olApp As Outlook.Application = New Outlook.Application (works OK if Outlook is closed but throws error if Outlook is already open)

ERROR (if Outlook is already open):
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

If I use the CreateObject method save result (it works only if Outlook is not running)

olApp = CType(CreateObject("OUTLOOK.Application"), Outlook.Application)

ERROR (if Outlook is already open):
Cannot create ActiveX component.

How can I create an Outlook email if Outlook is already open? (My app already gives the user the choices to send mail via SMTP and Default Mail but I also want to give the user the option to use Outlook too.)

0
Comment
Question by:CarlK
8 Comments
 
LVL 30

Expert Comment

by:IanTh
ID: 35123667
hmm

hope this points in the right direction

http://www.serverwatch.com/tutorials/article.php/1474711/Send-E-mail-Using-Microsoft-Outlook-Automation.htm

as in his intro he says it chaecks if poutlook is open or not so he some code that achieves what your trying to do
0
 

Author Comment

by:CarlK
ID: 35123747
Thanks, but the GetObject does not work either.

With Outlook OPEN already the line;

olApp = CType(GetObject("", "Outlook.application"), Outlook.Application)

throws a "Cannot create ActiveX component." error.

Perhaps the GetObject/CreateObject methods works differently for Windows 7 and/or Office 2010 because there are many many articles like the one you referenced which show the GetObject and CreateObject as the way to open Outlook, yet if fails for me.
0
 
LVL 30

Expert Comment

by:IanTh
ID: 35123916
0
 

Author Comment

by:CarlK
ID: 35124145
Sorry, If you read the entire thread you'll see that it did not fix the user's problem.
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 4

Expert Comment

by:dailypcguy
ID: 35125081
Office 32 or 64bit?
0
 

Author Comment

by:CarlK
ID: 35128494
Windows 7 64 bit, Office 2010 32 bit
0
 

Author Comment

by:CarlK
ID: 35143000
Okay so here's what I have discovered. In all my previous test I was running my app in the Visual Studio 2010 IDE. The GetObject method doesn't work as expected. If I build the project and run it as a stand alone app (EXE file) the code works fine.  

This code work in the compiled executable

Dim olApp As Outlook.Application = Nothing
  Try
       'try to use existing instance of Outlook
       olApp = CType(GetObject("", "Outlook.application"), Outlook.Application)
   Catch ex As Exception
        'Outlook is not running. Create a new instance
        Try
           olApp = CType(CreateObject("OUTLOOK.Application"), Outlook.Application)
         Catch exc As Exception
            strErrMsg = "Outlook Send mail Error." + vbCrLf + vbCrLf
            strErrMsg += ex.Message
            GoTo sub_Exit
         End Try
   End Try
0
 
LVL 1

Accepted Solution

by:
cstaff16 earned 500 total points
ID: 35204216
I was encountering the same issue in an App and figured out what was causing it.
On a Vista/Win 7 machine if you have UAC turned on and your process is started with elevated privilages (Run as Administrator), but outlook is started normal (without Run as Administrator), then you cannot CoCreate an instance of it.  The only solution we came up with was to run both at the same level or turn of UAC if that is an option.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
exchange 2013 4 40
Duplicating a tab page content to another in TabControl control 11 40
Run time Error 4 34
Windows Update not finsihing 10 26
By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now