Hello
First of all apologies for cross posting as I have posted this question on the MSDN network; I'm in a real bind and need some help to meet a deadline.
I'm writing a sub to create an email in Outook 2010 from a vb application designed in Visual Basic 2010 Express. I have added the Microsoft Outlook 14.0 Object Library, Microsoft Outlook View Control and Microsoft Office 14.0 Object Library to my references but the code below returns a number of errors along the lines of:
outlook._Namespace is not defined
outlook.Application is not defined.
outlook is not declared. It may be inaccessible due to its protection level.
Code is as follows:
Dim OutlookMessage As outlook.MailItem
Dim AppOutlook As New outlook.Application
Dim objNS As outlook._NameSpace = AppOutlook.Session
Dim objFolder As outlook.MAPIFolder
objFolder = objNS.GetDefaultFolder(outlook.OlDefaultFolders.olFolderDrafts)
Try
OutlookMessage = AppOutlook.CreateItem(outlook.OlItemType.olMailItem)
Dim Recipents As outlook.Recipients = OutlookMessage.Recipients
Recipents.Add("myemail@hotmail.com")
OutlookMessage.Subject = "Sending through Outlook"
OutlookMessage.Body = "Testing outlook Mail"
OutlookMessage.BodyFormat = outlook.OlBodyFormat.olFormatHTML
OutlookMessage.Save()
OutlookMessage.Move(objFolder)
Catch ex As Exception
MessageBox.Show("Mail could not be sent")
Finally
OutlookMessage = Nothing
AppOutlook = Nothing
End Try
Not sure what still remains to be referenced here? I'm having the same problem using Word classes as well. The program I'm building depends on using outlook to send emails and creating Word documents therefore I'm really stuck until I can work out how to get them working.
First of all apologies for cross posting as I have posted this question on the MSDN network; I'm in a real bind and need some help to meet a deadline.
I'm writing a sub to create an email in Outook 2010 from a vb application designed in Visual Basic 2010 Express. I have added the Microsoft Outlook 14.0 Object Library, Microsoft Outlook View Control and Microsoft Office 14.0 Object Library to my references but the code below returns a number of errors along the lines of:
outlook._Namespace is not defined
outlook.Application is not defined.
outlook is not declared. It may be inaccessible due to its protection level.
Code is as follows:
Dim OutlookMessage As outlook.MailItem
Dim AppOutlook As New outlook.Application
Dim objNS As outlook._NameSpace = AppOutlook.Session
Dim objFolder As outlook.MAPIFolder
objFolder = objNS.GetDefaultFolder(outlook.OlDefaultFolders.olFolderDrafts)
Try
OutlookMessage = AppOutlook.CreateItem(outlook.OlItemType.olMailItem)
Dim Recipents As outlook.Recipients = OutlookMessage.Recipients
Recipents.Add("myemail@hotmail.com")
OutlookMessage.Subject = "Sending through Outlook"
OutlookMessage.Body = "Testing outlook Mail"
OutlookMessage.BodyFormat = outlook.OlBodyFormat.olFormatHTML
OutlookMessage.Save()
OutlookMessage.Move(objFolder)
Catch ex As Exception
MessageBox.Show("Mail could not be sent")
Finally
OutlookMessage = Nothing
AppOutlook = Nothing
End Try
Not sure what still remains to be referenced here? I'm having the same problem using Word classes as well. The program I'm building depends on using outlook to send emails and creating Word documents therefore I'm really stuck until I can work out how to get them working.