Results 1 to 6 of 6
  1. #1
    EvanScamman
    Guest

    Use VB to Paste from clipboard to body of mail msg (Outlook 2000)

    I'm trying to use automation to copy from an excel spreadsheet into an Outlook mail message:
    I don't know how to use the paste command so the following code gives an error.
    Please help me if you can! Thanks!

    Private Sub Command1_Click()
    Dim myOLApp As New Outlook.Application
    Dim myOLItem As Outlook.MailItem
    Set myOLItem = myOLApp.CreateItem(olMailItem)
    With myOLItem
    .Subject = "Sample item"
    .Body.Paste
    End With
    myOLItem.Display

    End Sub

  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: Use VB to Paste from clipboard to body of mail msg (Outlook 2000)

    Sadly, in the Outlook editor, the Body is just a big string field. You can set the body equal to a string. To retrieve the clipboard as plain text, search the board archives for DataObject, which is a method of accessing the clipboard in the MSForms library.

  3. #3
    5 Star Lounger
    Join Date
    May 2001
    Location
    Washington, USA
    Posts
    750
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Use VB to Paste from clipboard to body of mail msg (Outlook 2000)

    It's possible to copy a block of cells into an RTF format mail item and have them show up as a table, or even embed a worksheet in the body via Insert | Object. Seems like there ought to be a way to do this via code. But I've never looked into it, so it's just the voice of optimism (or ignorance) speaking.

  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: Use VB to Paste from clipboard to body of mail msg (Outlook 2000)

    I must confess complete unfamiliarity with RTF mail. The general problem in the object model is there's no insertion point. This is the kind of thing I use SendKeys for...

  5. #5
    EvanScamman
    Guest

    Re: Use VB to Paste from clipboard to body of mail msg (Outlook 2000)

    I suspected that SendKeys might be my only option, but i don't know how to make it send the Keys to Outlook - would you mind giving me and example - that would really help. Thanks!

  6. #6
    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: Use VB to Paste from clipboard to body of mail msg (Outlook 2000)

    For example, I add a header from a text file to a message with this:

    SendKeys "%j", True 'reposition in subject line
    SendKeys "{TAB}", True 'tab into body
    Dim FlNum As Integer, sOneLine As String
    FlNum = FreeFile
    Open "c:header.txt" For Input As #FlNum
    While Not EOF(FlNum) 'process halts when at the end of the file
    Line Input #FlNum, sOneLine 'read entire line of text into string var
    SendKeys sOneLine, True
    SendKeys "{ENTER}", True
    Wend
    Close #FlNum

    To paste from the clipboard to the insertion point, wherever that may be, use:

    SendKeys "^v"

Posting Permissions

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