M
Matt Jensen
Howdy
Developing an Excel/VBA app that creates and displays a new Outlook email
with the Excel workbook attached and I need to allow the user to edit the
body of the email.
I was wondering if there's any simple method of the Outlook object that I
can use to notify my Excel workbook that this email created and displayed
was actually sent?
My (cut-down) code looks like this:
Option Explicit
Sub A10SendEmail()
'dimension variables
Dim vaDetailChanges As Variant
Dim vaAuthorisationChanges As Variant
Dim i As Integer
Dim wb As Workbook
Dim boolDetailChanges, boolNewAuthorisations As Boolean
Dim strEmail, strProjectName, strFromName As String
Set wb = ActiveWorkbook
wb.Save
'my code
vaDetailChanges = Worksheets("Data-DetailsUpdates").UsedRange.Value
'Get variables to put in email fields
strEmail =
Worksheets("Data-Application").Range("projectvar_DLPMOEmail").Value
strProjectName =
Worksheets("Data-ProjectDetails").Range("projectvar_ProjectName").Value
strFromName =
Worksheets("Data-ProjectDetails").Range("projectvar_PM").Value
' Outlook Automation
' Start Outlook - existing instance will be used if it is already
running
Dim olApp As Object 'Outlook.Application
Set olApp = CreateObject("Outlook.Application")
'Create an email
Dim olMail As Object 'Outlook.MailItem
'Set olMail = olApp.createitem(olMail)
Set olMail = olApp.createitem(0)
'set email recipient
olMail.To = strEmail
'create base part of HTML email body
olMail.HTMLBody = _
"Dear PMO,<br />"
'create body of email
' my code here
'set closing part of email
olMail.HTMLBody = olMail.HTMLBody & _
"Regards,<br />" & strFromName & "<br /> "
'add checklist as attachment
olMail.Attachments.Add wb.FullName, 1, 1, wb.Name
'display new email ready to be sent
olMail.Display
'Clean up
Set olMail = Nothing
Set olApp = Nothing
'THIS IS THE FLAG VARIABLE USED FOR WHETHER EMAIL WAS ACTUALLY SENT
'Currently I assumes that running this sub means the email was sent, but
would like to know for sure if possible...?
Worksheets("Data-Application").Range("appvar_EmailRecommended").Value =
False
End Sub
Thanks for any help
Cheers
Matt
Developing an Excel/VBA app that creates and displays a new Outlook email
with the Excel workbook attached and I need to allow the user to edit the
body of the email.
I was wondering if there's any simple method of the Outlook object that I
can use to notify my Excel workbook that this email created and displayed
was actually sent?
My (cut-down) code looks like this:
Option Explicit
Sub A10SendEmail()
'dimension variables
Dim vaDetailChanges As Variant
Dim vaAuthorisationChanges As Variant
Dim i As Integer
Dim wb As Workbook
Dim boolDetailChanges, boolNewAuthorisations As Boolean
Dim strEmail, strProjectName, strFromName As String
Set wb = ActiveWorkbook
wb.Save
'my code
vaDetailChanges = Worksheets("Data-DetailsUpdates").UsedRange.Value
'Get variables to put in email fields
strEmail =
Worksheets("Data-Application").Range("projectvar_DLPMOEmail").Value
strProjectName =
Worksheets("Data-ProjectDetails").Range("projectvar_ProjectName").Value
strFromName =
Worksheets("Data-ProjectDetails").Range("projectvar_PM").Value
' Outlook Automation
' Start Outlook - existing instance will be used if it is already
running
Dim olApp As Object 'Outlook.Application
Set olApp = CreateObject("Outlook.Application")
'Create an email
Dim olMail As Object 'Outlook.MailItem
'Set olMail = olApp.createitem(olMail)
Set olMail = olApp.createitem(0)
'set email recipient
olMail.To = strEmail
'create base part of HTML email body
olMail.HTMLBody = _
"Dear PMO,<br />"
'create body of email
' my code here
'set closing part of email
olMail.HTMLBody = olMail.HTMLBody & _
"Regards,<br />" & strFromName & "<br /> "
'add checklist as attachment
olMail.Attachments.Add wb.FullName, 1, 1, wb.Name
'display new email ready to be sent
olMail.Display
'Clean up
Set olMail = Nothing
Set olApp = Nothing
'THIS IS THE FLAG VARIABLE USED FOR WHETHER EMAIL WAS ACTUALLY SENT
'Currently I assumes that running this sub means the email was sent, but
would like to know for sure if possible...?
Worksheets("Data-Application").Range("appvar_EmailRecommended").Value =
False
End Sub
Thanks for any help
Cheers
Matt