?
Solved

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

Posted on 2011-03-13
8
Medium Priority
?
3,792 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 

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
 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

719 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