Link to home
Start Free TrialLog in
Avatar of ret2855
ret2855

asked on

I have a macro to send emails using excel, but i would like it to set a 10 day flag in outlook automatically as well on the SENT email.

I have searched but have been unable to find a solid solution to create the follow up flag in outlook using excel.  I need to set the reminder for myself to follow back up on the email with the recipient.  Is this even possible?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ret2855
ret2855

ASKER

Ryan, just thought about this but will this code work if i am manually sending the emails after excel generates them (i.e. using ".display" instead of "send".  My code is below, any suggestions on how to incorporate your code into mine if possible?
Sub Procedure1()

  Dim IsCreated As Boolean
  Dim i As Long
  Dim PdfFile As String, Title As String
  Dim OApp As Object, OMail As Object, signature As String
  
  ' Not sure for what the Title is
  Title = Range("A1")

  ' Define PDF filename
  PdfFile = ActiveWorkbook.FullName
  i = InStrRev(PdfFile, ".")
  If i > 1 Then PdfFile = Left(PdfFile, i - 1)
  PdfFile = PdfFile & "_" & Sheets("Christmas").Name & ".pdf"
 
  ' Export activesheet as PDF
  With Sheets("Christmas")
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard<wbr ></wbr><wbr ></wbr>, IncludeDocProperties:=True<wbr ></wbr><wbr ></wbr>, IgnorePrintAreas:=False, OpenAfterPublish:=False
  End With
 
  ' Use already open Outlook if possible
  On Error Resume Next
  Set OApp = CreateObject("Outlook.Appl<wbr ></wbr><wbr ></wbr>ication")
    Set OMail = OApp.CreateItem(0)
    With OMail
    .Display
    End With
        signature = OMail.HTMLbody
  If Err Then
    Set OApp = CreateObject("Outlook.Appl<wbr ></wbr><wbr ></wbr>ication")
    IsCreated = True
  End If
  OutlApp.Visible = True
  On Error GoTo 0
  
  ' Prepare e-mail with PDF attachment
  With OMail
   
    ' Prepare e-mail
    .Subject = "Christmas: " & Sheets("Information").Rang<wbr ></wbr><wbr ></wbr>e("f12") & " - " & Sheets("Information").Rang<wbr ></wbr><wbr ></wbr>e("p24")
    .To = Sheets("Information").[L35<wbr ></wbr><wbr ></wbr>] ' <-- Put email of the recipient here
    '.CC = "..." ' <-- Put email of 'copy to' recipient here
    .HTMLbody = "<html><font face=Calibri><font size=4><p>" & Sheets("Information").Rang<wbr ></wbr><wbr ></wbr>e("f35") & "," & "<br>" & "<br>" _
         & "CHRISTMAS PARTIES" & Sheets("Information").Rang<wbr ></wbr><wbr ></wbr>e("f20") & "." _
         & "  ARE LOADS OF FUN." _
         & "<br>" & "<br>" & "Thank You," & "<br>" _
         & signature
          
    .Attachments.Add PdfFile
    
    ' Try to send
    On Error Resume Next
    .Display
    Application.Visible = True
         
  End With
 
  ' Delete PDF file
  Kill PdfFile
 
  ' Quit Outlook if it was created by this code
  If IsCreated Then OutlApp.Quit
 
  ' Release the memory of object variable
  Set OMail = Nothing
  Set OApp = Nothing
 

End Sub

Open in new window

I'm not too sure if .Display will eventually send out the email, but I can see you're deleting the pdf after .Display ?

(sorry as I don't have Outlook installed on my home laptop so I can't really test this as well as test the integrated scripts below. I will only come back to work next Mon)

you probably can incorporate my codes into your codes to become as follows:
Sub Procedure1()

  Dim IsCreated As Boolean
  Dim i As Long
  Dim PdfFile As String, Title As String
  Dim OApp As Object, OMail As Object, signature As String
  
  ' Not sure for what the Title is
  Title = Range("A1")

  ' Define PDF filename
  PdfFile = ActiveWorkbook.FullName
  i = InStrRev(PdfFile, ".")
  If i > 1 Then PdfFile = Left(PdfFile, i - 1)
  PdfFile = PdfFile & "_" & Sheets("Christmas").Name & ".pdf"
 
  ' Export activesheet as PDF
  With Sheets("Christmas")
    .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 OApp = CreateObject("Outlook.Application")
    Set OMail = OApp.CreateItem(0)
    With OMail
    .Display
    End With
        signature = OMail.HTMLbody
  If Err Then
    Set OApp = CreateObject("Outlook.Application")
    IsCreated = True
  End If
  OutlApp.Visible = True
  On Error GoTo 0
  
  ' Prepare e-mail with PDF attachment
  With OMail
   
    ' Prepare e-mail
    .Subject = "Christmas: " & Sheets("Information").Range("f12") & " - " & Sheets("Information").Range("p24")
    .To = Sheets("Information").[L35] ' <-- Put email of the recipient here
    '.CC = "..." ' <-- Put email of 'copy to' recipient here
    .HTMLbody = "<html><font face=Calibri><font size=4><p>" & Sheets("Information").Range("f35") & "," & "<br>" & "<br>" _
         & "CHRISTMAS PARTIES" & Sheets("Information").Range("f20") & "." _
         & "  ARE LOADS OF FUN." _
         & "<br>" & "<br>" & "Thank You," & "<br>" _
         & signature
          
    .Attachments.Add PdfFile
    
    'Add flag and reminder
    .MarkAsTask olMarkNextWeek
    .TaskStartDate = Date + 10
    .TaskDueDate = Date + 10
    .FlagRequest = "Reminder"
    .ReminderSet = True
    .ReminderTime = Date + 10
    
    ' Try to send
    On Error Resume Next
    .Display
    Application.Visible = True
         
  End With
 
  ' Delete PDF file
  Kill PdfFile
 
  ' Quit Outlook if it was created by this code
  If IsCreated Then OutlApp.Quit
 
  ' Release the memory of object variable
  Set OMail = Nothing
  Set OApp = Nothing

End Sub

Open in new window

on a separate note, there are some random invalid chars within your codes "<wbr ></wbr><wbr ></wbr>", you may take note of this...
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.