I am learning VBA, but for the time being I am not that good and I found this macro:

Scheduled and recurring email in Outlook?

It sends an email thanks to a scheduled appointment set in the calendar.

Could someone maybe help me complete it so that it is possible to have an option to send an attachment too?

[EDIT] This is the script I modified, but it still does not work.Could you please just give me an indication?

    Private Sub Application_Reminder(ByVal Item As Object)
      Dim objMsg As MailItem
      Dim myAttachments As Outlook.Attachments
      Set objMsg = Application.CreateItem(olMailItem)
      Set myAttachments = objMsg.Attachments
    If Item.MessageClass <> "IPM.Appointment" Then
      Exit Sub
    End If

    If Item.Categories <> "Blue Category" Then
      Exit Sub
    End If

      objMsg.To = Item.Location
      objMsg.Subject = Item.Subject
      objMsg.Body = Item.Body
      myAttachments.Add "C:\Test.txt", _

      Set objMsg = Nothing
    End Sub

I think the problem is that the attachment is defined as something linked to Outlook whereas the MailItem was not. The macro worked well before inserting the few lines about the attachment, now it does not even send a mail anymore.

  • 2
    Welcome so SU! We're not a script writing service. What have you got/tried so far, and where are you getting stuck exactly? Have you checked with MSDN yet? Perhaps starting with this: Attachments.Add Method (Outlook) Sep 12 '14 at 19:35
  • Thanks, I have tried to combine it with msdn.microsoft.com/en-us/library/office/…, but it did not work since I am only a beginner in VBA. (Did not click on your link, it turns out to be the same)
    – Nre
    Sep 12 '14 at 19:39
  • 1
    Ok, since we can't read your mind, please edit your question and post the code you have created in attempts to use the Attachments. :) Also include/describe the results of your code, and/or any run-time errors you're encountering. Sep 12 '14 at 19:41
  • Sorry I did not post the script, since I did (almost) no changes and I guess it is a matter of one line I thought it was not relevant. You are all doing a great job here, please excuse me if my first post was not well understood.
    – Nre
    Sep 12 '14 at 23:35

You were so close! All you need to do is to remove the trailing underscore and comma from the end of the line

myAttachments.Add "C:\Test.txt", _

It should simply be

myAttachments.Add "C:\Test.txt"

I tried your code with that change, and it worked just fine.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.