Results 1 to 4 of 4
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,470
    Thanks
    30
    Thanked 62 Times in 58 Posts

    macro to send a PDF file (2003-2007)

    I would like a macro in Outlook that would take the selected contacts (user will CTRL+click those needed) and attach to them a PDF file from a given directory, given name.

    Could someone suggest the code for this?

    Unlike Word or Excel, there doesn't seem to be a "record" option in Outlook, or I'm missing something.

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

    Re: macro to send a PDF file (2003-2007)

    Do you mean that you want to create an e-mail message with the selected contacts as recipients and the PDF file as attachment?

    BTW no, Outlook doesn't have a macro recorder, sadly.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,470
    Thanks
    30
    Thanked 62 Times in 58 Posts

    Re: macro to send a PDF file (2003-2007)

    Exactly.

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

    Re: macro to send a PDF file (2003-2007)

    Here is such a macro. Modify the constant at the beginning of the code as needed.

    Sub Msg2SelectedContacts()
    Const strAttachment = "CocsTest.pdf"
    Dim sel As Selection
    Dim msg As MailItem
    Dim i As Integer
    Set sel = ActiveExplorer.Selection
    If sel.Count = 0 Then
    MsgBox "No contacts selected!", vbExclamation
    Exit Sub
    End If
    Set msg = CreateItem(olMailItem)
    With msg
    For i = 1 To sel.Count
    .Recipients.Add Name:=sel.Item(i)
    Next i
    .Recipients.ResolveAll
    .Attachments.Add Source:=strAttachment
    .Display
    End With
    End Sub

    When you run the macro, you'll be warned that a program is trying to access the address book, and asked whether you want to allow this.
    See <post:=488,173>post 488,173</post:> for ways to suppress this warning.

Posting Permissions

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