Solved

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

Posted on 2011-03-13
8
3,614 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:CarlK
Comment Utility
Sorry, If you read the entire thread you'll see that it did not fix the user's problem.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:dailypcguy
Comment Utility
Office 32 or 64bit?
0
 

Author Comment

by:CarlK
Comment Utility
Windows 7 64 bit, Office 2010 32 bit
0
 

Author Comment

by:CarlK
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.

763 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