Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Mar 2001
    Location
    LA, California, USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    e-mail to recipient (with formatting) using vba (2000)

    Using VBA, I am trying to send a Word document as the body of a e-mail while retaining the formatting. All the methods I have tried, with the exception of using SendKeys to simulate clicking the appropriate menu item, result in a loss of formatting. Using SendKeys is not a solution either, since I cannot set the recipients and subject from VBA. I cannot even use SendKeys to tab through the fields - it just puts the text I enter in the body, not it the correct fields.

    TIA for any help,
    Sean

  2. #2
    Lounger
    Join Date
    Mar 2001
    Location
    LA, California, USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: e-mail to recipient (with formatting) using vba (2000)

    I was finally able to do it by copying the active document content, opening an Outlook (2000) mail item and pasting the document into the body. Setting the recipients and subject for an Outlook message is not problem. BUT, there has to be a better way to do this. I will use what works for the time being, but I cannot be the only one who has wanted to do this.

    Thanks for any ideas,
    Sean

  3. #3
    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: e-mail to recipient (with formatting) using vba (2000)

    As you may have figured out by now, you can open the addressing fields using either of these commands:

    ActiveWindow.EnvelopeVisible = True

    CommandBars.FindControl(ID:=3738).Execute

    But like you, I do not see any way to guarantee the location of the insertion point after doing this. (If the message has not been sent previously, I am in the To field, but YMMV.)

    I noticed that when I send a message this way, it arrives as an HTML message body. That gave me the idea that I could create an HTML version of the document using Word's SaveAs method, and then assign that to the .HTMLBody of an Outlook message. Bingo!

    See the attached module (which you can save, rename with a .BAS extension, and import into a Word template or document for testing. Does it work for you?
    Attached Files Attached Files

  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: e-mail to recipient (with formatting) using vba (2000)

    Well, my process is not perfect: pictures from my PC are linked rather than embedded (and the links are relative paths to boot). But it seems to work well for text based on my tests so far. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> Enough fun for one night.

  5. #5
    Lounger
    Join Date
    Mar 2001
    Location
    LA, California, USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: e-mail to recipient (with formatting) using vba (2000)

    Thanks for the idea. I did not say before that I am doing this from Access (2000), which does not allow you export a report to html, but does to rtf. I then open the rtf file in word, copy the content (appWord.activeDocument.Content.Copy), create a new Outlook mail item (like your code does), set the to and subject field values and paste the rtf content into the body. It works fine (I don't need images, so I haven't tried that), but I just thought I should be able to do it right from Word in a simpler manner, without relying on SendKeys, etc.

    Perhaps I'll modify my code to create a menu button for "send to mail recipient" from Access, which only has "as attachment" for reports.

    Thanks,
    Sean

Posting Permissions

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