Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create an email from VB.net.
The code is as follows

VB
Imports Outlook = Microsoft.Office.Interop.Outlook
Public Class InputForm
Private Sub EmailTeam_Click(sender As Object, e As EventArgs) Handles EmailTeam.Click

        Dim Subject As String
        Dim Recipient As String
        Dim Message As String
        Subject = "My Team"
        Recipient = "myemail@address"
        Message = " Team details"
        SendOutlookMail(Subject, Recipient, Message)
    End Sub
    Public Sub SendOutlookMail(Subject As String, Recipient As _
String, Message As String)

        On Error GoTo errorHandler
        Dim oLapp As Outlook.Application
        Dim oItem As Object
       
        oLapp = CreateObject("Outlook.application")
        oItem = oLapp.CreateItem(0)

        With oItem
            .Subject = Subject
            .To = Recipient
            .body = Message
            .Display()
            '.Send()
        End With

        oLapp = Nothing
        oItem = Nothing


        Exit Sub

errorHandler:
        oLapp = Nothing
        oItem = Nothing
        Exit Sub


    End Sub
End Class 


But when it gets to
oLapp = CreateObject("Outlook.application")
it jumps to the errorHandler: and exits the sub routine.
Why does CreateObject("Outlook.application") not work?
I am a beginner so any help is gratefully received.

Dave


[edit: updated question title /manchanx]
Posted
Updated 22-Mar-15 1:19am
v3
Comments
ZurdoDev 19-Mar-15 16:29pm    
Why doesn't it work? We could guess but I'm sure the error would tell you why. Please share it.
[no name] 19-Mar-15 16:43pm    
I don't know a lot about VB and I just had to google that "errorHandler:" thing. From what I quick-read there it's deprecated. Use try-catch-finally instead (see https://msdn.microsoft.com/en-us/library/fk6t46tz.aspx). It will give you in most cases a decent error (exception) message that gives you a clue about what went wrong. If that message doesn't help you to resolve the issue, post the message here please.
Dave the Golfer 19-Mar-15 16:55pm    
I do not get an error message but when I have run my code I get this output.

'MatchManagement.vshost.exe' (CLR v4.0.30319: MatchManagement.vshost.exe): Loaded 'D:\My Documents on D\Visual Studio Projects\Match Management Application\MatchManagement\bin\Debug\MatchManagement.exe'. Symbols loaded.
'MatchManagement.vshost.exe' (CLR v4.0.30319: MatchManagement.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'. Cannot find or open the PDB file.
'MatchManagement.vshost.exe' (CLR v4.0.30319: MatchManagement.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Remoting\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll'. Cannot find or open the PDB file.
'MatchManagement.vshost.exe' (CLR v4.0.30319: MatchManagement.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
A first chance exception of type 'System.Exception' occurred in Microsoft.VisualBasic.dll
The program '[4464] MatchManagement.vshost.exe' has exited with code -1 (0xffffffff).
Dave the Golfer 19-Mar-15 17:06pm    
Whilst debugging I set a breakpoint and used F11 to step through code.
Having got to the errorhandler I moved the arrow back to the start of the subroutine and carried on stepping.
On reaching the line oLapp = CreateObject("Outlook.application") I got the following error;
An unhandled exception of type 'System.Exception' occurred in Microsoft.VisualBasic.dll

Additional information: Cannot create ActiveX component.
[no name] 19-Mar-15 17:18pm    
I'm sorry, I'm unable to help you with this. I updated the title of your question to hopefully "attract" someone who can help you with this.

1 solution

I have now solved the problem.
I originally had Office 2007.
I loaded Office 365. When I was happy with 365 I unloaded Office 2007. This it seems damaged Office 365.
I have now run a repair and all is OK. Thanks for all your support.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900