Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using macro to add recipient name (XP)

    I want to use a macro within word to send the document as an attachment to a specific email address. The macro records without problem but I can not find a way to automate the placement of the address of the recipient in the "To:" box of the email.

    Any help would be appreciated

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Using macro to add recipient name (XP)

    So...you get a pop-up Outlook message window? If so, you are in luck, because Word can easily add addressees to a message in an Outlook window.

    The general strategy is to do this:
    1. <LI>Open your macro for editing
      <LI>Under Tools, References, set a reference to Microsoft Outlook object model
      <LI>Add something like the following once the message window has been created:
    <pre>Dim olApp As Outlook.Application
    Dim msgItem As Outlook.MailItem, msgRecip As Recipient
    Set olApp = GetObject(, "Outlook.Application")
    Set msgItem = olapp.ActiveInspector.CurrentItem
    ' The above code assumes that your message popped to the front
    With msgItem
    Set msgRecip = .Recipients.Add(NameOrAddress)
    msgRecip.Type = olTo 'or olCC or olBCC
    'Add more recipients as needed
    .Recipients.ResolveAll
    End With
    Set msgRecip = Nothing
    Set msgItem = Nothing
    Set olApp = Nothing</pre>

    If you are only sending to one recipient, you can change the middle part to:
    <pre>With msgItem
    .To = NameOrAddress
    .Recipients.ResolveAll
    End With</pre>

    Hope this helps. (I use 2000; in 2002, you might get a security warning on this!)

  3. #3
    New Lounger
    Join Date
    Mar 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using macro to add recipient name (XP)

    Very Neat, thanks for sharing the code. This works well. Do you know if there is any way of suppressing the security warning(s) and to just let the email go automatically?

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Using macro to add recipient name (XP)

    There's probably a more detailed discussion of that on the Oulook board. My rough memory is that you get the warning unless the software accessing Outlook is "trusted" in a certain way. You also can bypass the Outlook object model by editing your code to use Redemption (links on the Outlook board), a DLL that talks to Outlook through MAPI or Extended MAPI or something like that.

Posting Permissions

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