Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Australia
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sending Attachments via Outlook (XP/11.5614.5606)

    I want to send a PDF newsletter from Access after I have filtered a list of e-mail addresses. I have a strRecipients that stores
    the list in this format "someone@microsoft.com, fred@work.com, annie@home.com".

    From MS site (MKSB) I see details of an 'AttachmentPath' but I can't see how to reference my file "C:Newsletter.pdf" via the code.

    In the past I have been able to send attachments from within VBA code in Outlook using <pre>'.Attachments.Add "C:Newsletter.pdf"</pre>

    but I can't get it to do the same with this code.

    Pointers or suggestions most welcome, thanks...

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sending Attachments via Outlook (XP/11.5614.5606)

    You're on the right track. Once you have created an Outlook.MailItem object, you can add an item to its Attachments collection.

    You don't say what goes wrong. I am probably pointing out the obvious, but the line you posted won't do anything because the apostrophe at the start makes it into a comment.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Australia
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sending Attachments via Outlook (XP/11.5614.5606)

    Thanks Hans

    The apostrophe was accidentally inserted (or more correctly the closing single apostrophe was omitted) so it can be disregarded.

    My problem is this. Where do I make reference to the only file I wish to attach?
    Where or how do I make reference to my file to be attached by referencing the AttachmentPath?

    <pre> Sub SendMessage(Optional AttachmentPath)
    ' Sending e-mail with attachment
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachments
    Dim strRecipients As String

    ' following will be the string from the text box in Access
    strRecipients = "someone@microsoft.com, fred@work.com, annie@home.com"

    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")

    ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

    With objOutlookMsg
    ' Add the BCC recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add(strRecipients)
    objOutlookRecip.Type = olBCC

    '' Add the CC recipient(s) to the message.
    '' Set objOutlookRecip = .Recipients.Add("TBA")
    '' objOutlookRecip.Type = olCC

    ' Set the Subject, Body, and Importance of the message.
    .Subject = "Current Newsletter"
    .Body = "Please contact me if you wish to change e-mail details." & vbCrLf & vbCrLf
    .Importance = olImportanceHigh 'High importance


    ' Add attachments to the message.
    If Not IsMissing(AttachmentPath) Then
    Set objOutlookAttach = .Attachments.Add(AttachmentPath)
    End If

    .Send

    End With
    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing
    End Sub



    </pre>



    Thanks for your assistance.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sending Attachments via Outlook (XP/11.5614.5606)

    You must call this procedure as follows:

    SendMessage "C:Newsletter.pdf"

    or

    Call SendMessage("C:Newsletter.pdf")

    where C:Newsletter.pdf is the path and file name of the file you want to attach.

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Australia
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sending Attachments via Outlook (XP/11.5614.5606)

    You make it sound so simple - but of course, it worked. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •