Outlook Email & Reminder from Excel

rucker222

New Member
Joined
Mar 13, 2014
Messages
7
Hi All,

I've spent hours messing around with this now and just cant work it out and google is not getting me any closer :(
I've got an excel module which saves my workbook exports it to a pdf and then generates an email with the pdf attached.

Where I'm stuck is setting a follow up reminder for myself as the sender. I should point out that um using office 2010 but there are other people who will be using this from different versions so need to late bind everything.
In outlook when creating a new email if i click follow-up and select custom I have the option to "Flag for Me" and set a reminder. How can I add this to my current module?...

I've taken bits and pieces of VBA from all over the internet to make this so please excuse how messy it probably is.

Code:
Sub SaveFileAs()

    Dim CurrFile As String
    Dim WasSaved As Boolean
    Dim ret As Boolean
    Dim IsCreated As Boolean
    Dim i As Long
    Dim PdfFile As String, Title As String, mailBody As String
    Dim OutlApp As Object
    Dim cc_emailRng As Range, cl As Range
    
    Set cc_emailRng = Range("cc_emails")
    
    For Each cl In cc_emailRng
        scc = scc & ";" & cl.Value
    Next
    scc = Mid(scc, 2)
          
    On Error Resume Next
     
    WasSaved = False
    
    On Error Resume Next
    ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "\" & "RFI - " & Range("D9").Value & "_" & Range("H4").Value & ".xls"
    
    If Err.Number = 0 Then
        WasSaved = True
    
   
    End If
        
    On Error Resume Next
    
    If WasSaved = True Then
    
    
    
    CurrFile = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
    
    Else
        Err.Clear
        ret = Application.Dialogs(xlDialogSaveAs).Show
        
        If ret = True Then
        'saved with some name
        WasSaved = True
        End If
    End If
          
    On Error Resume Next
    
    If WasSaved = False Then
   
        MsgBox "Not Saved!" & vbNewLine & vbNewLine _
        & "If you are experiencing any problems " & vbNewLine & _
        "please contact ...", vbExclamation
    
    End If
    
    Title = "Request For Information - " & Range("D9").Value & "_" & Range("H4").Value
    ' Define PDF filename
    PdfFile = ActiveWorkbook.FullName
    i = InStrRev(PdfFile, ".")
    If i > 1 Then PdfFile = Left(PdfFile, i - 1)
    PdfFile = PdfFile & ".pdf"
 
    ' Export activesheet as PDF
    With ActiveSheet
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    End With
 
    ' Use already open Outlook if possible
    On Error Resume Next
    Set OutlApp = GetObject(, "Outlook.Application")
    
    If Err Then
        Set OutlApp = CreateObject("Outlook.Application")
        IsCreated = True
    End If
  
    If ActiveSheet.Shapes("Check Box 1").ControlFormat.Value = 1 Then
        mailBody = "Please note: Cost/Time Implications do apply. <br>"
    Else: mailBody = " "
    End If
  
  If WasSaved = True Then
   
    MsgBox "Excel Workbook Saved as: " & vbNewLine & _
    ActiveWorkbook.FullName & vbNewLine & vbNewLine & _
    "PDF Saved as: " & vbNewLine & _
    PdfFile & vbNewLine, , "Files Saved"
  
  End If
  
  On Error Resume Next
   
  OutlApp.Visible = True
  On Error GoTo 0
 
  ' Prepare e-mail with PDF attachment
  With OutlApp.CreateItem(0)
   
    ' Prepare e-mail
    .Display
    signiture = .HTMLBody
    '.SentOnBehalfOfName = Range("Originator").Value & "<" & Range("globalEmail") & ">"
    .Subject = Title
    .To = Range("email").Value ' <-- Put email of the recipient here
    .CC = scc ' <-- Put email of 'copy to' recipient here
    .HTMLBody = "<H3></H3>" & _
    "Attention:  " & Range("D8").Value & "<br><br>" _
    & "Please find Request for Information Number " & Range("H4").Value & " attached for " & Range("D9").Value & "<br><br>" _
    & "Originator:  " & Range("Originator").Value & "<br><br>" _
    & mailBody & "<br><br>" _
    & "Please Return Response To: ... Pty Ltd<br>" _
    & "Response Required by: " & Range("H8").Value & "<br>" _
    & "For the Attention of: " & Range("globalAttention").Value & "<br>" _
    & "Fax: " & Range("globalFax").Value & "<br>" _
    & "Telephone: " & Range("globalTelephone").Value & "<br>" _
    & "Email: " & Range("globalEmail").Value & "<br>" _
    & signiture
    .Attachments.Add PdfFile
    .FlagStatus = olFlagMarked
    .FlagRequest = "Follow up"
    .FlagDueBy = Format(DateAdd("d", -0, CDate(Range("H8").Value) & " 09:30 AM"))
   
    ' Try to send
    '.Send
    On Error Resume Next
    .Display
    Application.Visible = True
    If Err Then
      MsgBox "E-mail was not sent", vbExclamation
    Else
      'MsgBox "E-mail successfully sent", vbInformation
    End If
    On Error GoTo 0
   
  End With
  
  If WasSaved = False Then
    Kill PdfFile ' Delete PDF file
  End If
   
  ' Quit Outlook if it was created by this code
  'If IsCreated Then OutlApp.Quit
 
  ' Release the memory of object variable
  Set OutlApp = Nothing
  
 
End Sub

If anyone can help it would be greatly appreciated!!!

Cheers,

Lee.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi Michael,

Yeah I have come across that one but couldn't work out how to get it working for me...

any ides? :)
 
Upvote 0
Don't have Excel to try but this is set for 3pm
Someone else may be able to add to it
Code:
Sub SaveFileAs()

    Dim CurrFile As String
    Dim WasSaved As Boolean
    Dim ret As Boolean
    Dim IsCreated As Boolean
    Dim i As Long
    Dim PdfFile As String, Title As String, mailBody As String
    Dim OutlApp As Object
    Dim cc_emailRng As Range, cl As Range
    
    Set cc_emailRng = Range("cc_emails")
    
    For Each cl In cc_emailRng
        scc = scc & ";" & cl.Value
    Next
    scc = Mid(scc, 2)
          
    On Error Resume Next
     
    WasSaved = False
    
    On Error Resume Next
    ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "\" & "RFI - " & Range("D9").Value & "_" & Range("H4").Value & ".xls"
    
    If Err.Number = 0 Then
        WasSaved = True
    
   
    End If
        
    On Error Resume Next
    
    If WasSaved = True Then
    
    
    
    CurrFile = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
    
    Else
        Err.Clear
        ret = Application.Dialogs(xlDialogSaveAs).Show
        
        If ret = True Then
        'saved with some name
        WasSaved = True
        End If
    End If
          
    On Error Resume Next
    
    If WasSaved = False Then
   
        MsgBox "Not Saved!" & vbNewLine & vbNewLine _
        & "If you are experiencing any problems " & vbNewLine & _
        "please contact ...", vbExclamation
    
    End If
    
    Title = "Request For Information - " & Range("D9").Value & "_" & Range("H4").Value
    ' Define PDF filename
    PdfFile = ActiveWorkbook.FullName
    i = InStrRev(PdfFile, ".")
    If i > 1 Then PdfFile = Left(PdfFile, i - 1)
    PdfFile = PdfFile & ".pdf"
 
    ' Export activesheet as PDF
    With ActiveSheet
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    End With
 
    ' Use already open Outlook if possible
    On Error Resume Next
    Set OutlApp = GetObject(, "Outlook.Application")
    
    If Err Then
        Set OutlApp = CreateObject("Outlook.Application")
        IsCreated = True
    End If
  
    If ActiveSheet.Shapes("Check Box 1").ControlFormat.Value = 1 Then
        mailBody = "Please note: Cost/Time Implications do apply. "
    Else: mailBody = " "
    End If
  
  If WasSaved = True Then
   
    MsgBox "Excel Workbook Saved as: " & vbNewLine & _
    ActiveWorkbook.FullName & vbNewLine & vbNewLine & _
    "PDF Saved as: " & vbNewLine & _
    PdfFile & vbNewLine, , "Files Saved"
  
  End If
  
  On Error Resume Next
   
  OutlApp.Visible = True
  On Error GoTo 0
 
  ' Prepare e-mail with PDF attachment
  With OutlApp.CreateItem(olMailItem)
   
    ' Prepare e-mail
    .Display
    Signature = .HTMLBody
    '.SentOnBehalfOfName = Range("Originator").Value & "<" & Range("globalEmail") & ">"
    .Subject = Title
    .To = Range("email").Value ' <-- Put email of the recipient here
    .CC = scc ' <-- Put email of 'copy to' recipient here
    .HTMLBody = ""
" & _
    "Attention:  " & Range("D8").Value & "" _
    & "Please find Request for Information Number " & Range("H4").Value & " attached for " & Range("D9").Value & "" _
    & "Originator:  " & Range("Originator").Value & "" _
    & mailBody & "" _
    & "Please Return Response To: ... Pty Ltd" _
    & "Response Required by: " & Range("H8").Value & "" _
    & "For the Attention of: " & Range("globalAttention").Value & "" _
    & "Fax: " & Range("globalFax").Value & "" _
    & "Telephone: " & Range("globalTelephone").Value & "" _
    & "Email: " & Range("globalEmail").Value & "" _
    & signiture
    .Attachments.Add PdfFile
    .ReminderSet = True
    .ReminderTime = "15:00" 'set for 3pm
    '.FlagStatus = olFlagMarked
    '.FlagRequest = "Follow up"
    '.FlagDueBy = Format(DateAdd("d", -0, CDate(Range("H8").Value) & " 09:30 AM"))
   
    ' Try to send
    '.Send
    On Error Resume Next
    .Display
    Application.Visible = True
    If Err Then
      MsgBox "E-mail was not sent", vbExclamation
    Else
      'MsgBox "E-mail successfully sent", vbInformation
    End If
    On Error GoTo 0
   
  End With
  
  If WasSaved = False Then
    Kill PdfFile ' Delete PDF file
  End If
   
  ' Quit Outlook if it was created by this code
  'If IsCreated Then OutlApp.Quit
 
  ' Release the memory of object variable
  Set OutlApp = Nothing
  
 
End Sub
 
Upvote 0
Hi Michael,

Thanks, I gave that a go but didn't have any luck unfortunately, I did however manage to create a totally separate task with a reminder.

Unfortunately this is not really ideal as I will now have two copies of the PDF attachment on my outlook email account (one in the sent items & one attached to the new Task).

Also I liked the idea of having the reminder linked directly to the sent email message to make things easier to track and follow up.

below is what I have at the moment.

Code:
Sub SaveFileAs()

    Dim CurrFile As String
    Dim WasSaved As Boolean
    Dim ret As Boolean
    Dim IsCreated As Boolean
    Dim i As Long
    Dim PdfFile As String, Title As String, mailBody As String
    Dim OutlApp As Object
    Dim cc_emailRng As Range, cl As Range
    
    
    Set cc_emailRng = Range("cc_emails")
    
    For Each cl In cc_emailRng
        scc = scc & ";" & cl.Value
    Next
    scc = Mid(scc, 2)
          
    On Error Resume Next
     
    WasSaved = False
    
    On Error Resume Next
    ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "\" & "RFI - " & Range("D9").Value & "_" & Range("H4").Value & ".xls"
    
    If Err.Number = 0 Then
        WasSaved = True
    
   
    End If
        
    On Error Resume Next
    
    If WasSaved = True Then
    
    
    
    CurrFile = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
    
    Else
        Err.Clear
        ret = Application.Dialogs(xlDialogSaveAs).Show
        
        If ret = True Then
        'saved with some name
        WasSaved = True
        End If
    End If
          
    On Error Resume Next
    
    If WasSaved = False Then
   
        MsgBox "Not Saved!" & vbNewLine & vbNewLine _
        & "If you are experiencing any problems " & vbNewLine & _
        "please contact ...", vbExclamation
    
    End If
    
    Title = "Request For Information - " & Range("D9").Value & "_" & Range("H4").Value
    ' Define PDF filename
    PdfFile = ActiveWorkbook.FullName
    i = InStrRev(PdfFile, ".")
    If i > 1 Then PdfFile = Left(PdfFile, i - 1)
    PdfFile = PdfFile & ".pdf"
 
    ' Export activesheet as PDF
    With ActiveSheet
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    End With
 
    ' Use already open Outlook if possible
    On Error Resume Next
    Set OutlApp = GetObject(, "Outlook.Application")
    
    If Err Then
        Set OutlApp = CreateObject("Outlook.Application")
        IsCreated = True
    End If
  
    If ActiveSheet.Shapes("Check Box 1").ControlFormat.Value = 1 Then
        mailBody = "Please note: Cost/Time Implications do apply. 
"
    Else: mailBody = " "
    End If
  
  If WasSaved = True Then
   
    MsgBox "Excel Workbook Saved as: " & vbNewLine & _
    ActiveWorkbook.FullName & vbNewLine & vbNewLine & _
    "PDF Saved as: " & vbNewLine & _
    PdfFile & vbNewLine, , "Files Saved"
  
  End If
  
  On Error Resume Next
   
  OutlApp.Visible = True
  On Error GoTo 0
 
  ' Prepare e-mail with PDF attachment
  With OutlApp.CreateItem(0)
   
    ' Prepare e-mail
    .Display
    signiture = .HTMLBody
    '.SentOnBehalfOfName = Range("Originator").Value & "<" & Range("globalEmail") & ">"
    .Subject = Title
    .To = Range("email").Value ' <-- Put email of the recipient here
    .CC = scc ' <-- Put email of 'copy to' recipient here
    .HTMLBody = "" 
    & signiture
    .Attachments.Add PdfFile
    '.FlagStatus = olFlagMarked
    '.FlagRequest = "Follow up"
    '.FlagDueBy = Format(DateAdd("d", -0, CDate(Range("H8").Value) & " 09:30 AM"))
    
    With OutlApp.CreateItem(3)
        .Subject = Title
        '.StartDate = Format(DateAdd("d", -0, CDate(Range("H8").Value)))
        .DueDate = Format(DateAdd("d", -0, CDate(Range("H8").Value)))
        .ReminderPlaySound = True
        .ReminderSet = True
        .ReminderTime = .DueDate - 1
        .Body = "Follow up RFI Number " & Range("H4").Value & " attached for " & Range("D9").Value & vbNewLine _
        & "To the Attention of:  " & Range("D8").Value & vbNewLine _
        & "Originator:  " & Range("Originator").Value & vbNewLine _
        & "Response Required by: " & Range("H8").Value
        .Attachments.Add PdfFile
        .Display
        '.Save
    End With
    
   
    ' Try to send
    '.Send
    On Error Resume Next
    .Display
    Application.Visible = True
    If Err Then
      MsgBox "E-mail was not sent", vbExclamation
    Else
      'MsgBox "E-mail successfully sent", vbInformation
    End If
    On Error GoTo 0
   
  End With
  
  If WasSaved = False Then
    Kill PdfFile ' Delete PDF file
  End If
   
  ' Quit Outlook if it was created by this code
  'If IsCreated Then OutlApp.Quit
 
  ' Release the memory of object variable
  Set OutlApp = Nothing
  Set OutlApp = Nothing
 
End Sub

Getting there, so close but yet still so far :confused:
 
Upvote 0

Forum statistics

Threads
1,215,334
Messages
6,124,319
Members
449,154
Latest member
pollardxlsm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top