Outlook add in: Saved email gives error "Object reference not set..."
Hi
I am creating a new email in Outlook 2007 using an VS2008 add-in, and save it to local disc.
It creates the new Mailitem, saves it as MSG, and I can open it from local disc (by double clicking on file c:\temp.msg) while outlook is still open.
When I close outlook, and then try to open the file from disc (by double clicking on the file c:\temp.msg), it does show the email message, BUT with an error messagebox saying : "Object reference not set to an instance of an object."
Anyone have an idea what could be wrong?
Code:
Imports Microsoft.Office.Interop.Outlook
Public Class save_message
Private Sub btn_send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_send.Click
Dim oApp As Outlook.Application
Dim oMsg As Outlook.MailItem
oApp = New Outlook.Application()
oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
With oMsg
.To = "[email protected]"
.Subject = "this is the subject"
.Body = "this is the body"
End With
oMsg.SaveAs("c:\temp.msg", OlSaveAsType.olMSG)
End Sub
Re: Outlook add in: Saved email gives error "Object reference not set..."
When you open a mail directly from the desktop, I doubt the btn_send_Click event fires...
Can I see the code for the rest of the Addin?
Also when you get this error, Which line does it highlight, in case you debug it?
Re: Outlook add in: Saved email gives error "Object reference not set..."
Hi
Ok I will expand a bit.
I created an add-in which pops up a Windows form within outlook on startup.
In this windows form I have a button called "btn_send", and contains the above code.
When I click the send button, it saves a *.MSG file on my disk.
I can open this file manually browsing to c:\temp.msg and doubleclicking on this file, no errors. All is good.
BUT, whenever I close Outlook, and try to manually open the c:\temp.msg file from explorer, it gives the error "Object reference not set..."
http://www.davidsmit.za.net/Images/Untitled.jpg
Re: Outlook add in: Saved email gives error "Object reference not set..."
Attach the addin, let me test it for you. I am more curious on the application open event...
1 Attachment(s)
Re: Outlook add in: Saved email gives error "Object reference not set..."
It is attached.
This addin creates a GOGO shortcut under outlook's FILE> menu.
when clicked it opens the windows form.
Re: Outlook add in: Saved email gives error "Object reference not set..."
hold on i think i found my problem, will report back just now
Re: Outlook add in: Saved email gives error "Object reference not set..."
Ok looks like it is because of a "catch ex as exception" section i had in This.Addin.vb
Outlook didnt give an error on compile, but it doesnt like to catch as exception, or im doing something wrong.
if i try
Code:
Try
Catch ex As Exception
End Try
in form1.vb, outlook gives this error:
Quote:
Catch cannot catch type microsoft.office.interop.outlook.exception because it is not system.excetion or a class that inherits from system.exception
so i removed the TRY from ThisAddIn.VB , now the email opens up without trouble.
Thanks koolsid fom helping me find my problem.