I am creating an add-in that lets users click a button and it opens a new email and auto fills fields and lets them edit the body before sending the email.
I am getting an error that does not let me use Outlook.Application
Error BC30111 'Application' is an interface type and cannot be used as an expression.
What am I doing wrong?
My Code:
Imports Microsoft.Office.Interop.Outlook
Imports Microsoft.Office.Tools.Ribbon
Public Class Ribbon1
Private olMailItem As Object
Private olImportanceHigh As OlImportance
Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
Dim obApp As Object
Dim NewMail As MailItem
obApp = Outlook.Application
NewMail = obApp.CreateItem(olMailItem)
'You can change the concrete info as per your needs
With NewMail
.Subject = " Test Email"
.To = "example@mail.com"
.Body = "This is just a test email template with Outlook VBA" & vbCrLf & vbCrLf & vbCrLf & "Yours Truly," & vbCrLf & vbCrLf & "John Smith"
.Importance = olImportanceHigh
.Display
End With
obApp = Nothing
NewMail = Nothing
End Sub
End Class