Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Chicago, Illinois, USA
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copy/paste from Word to Outlook item (vbscript/Office 2k/sr1 (word to Outlook))

    Hi all. I have a web-based application (as a folder home page in Outlook) that generates (a) a Word document (oDoc) with a named table in it (tblSchedule) full of data AND ([img]/forums/images/smilies/cool.gif[/img] a mail item based on a custom form (oFinalSchedule). I am trying to copy/paste or insert the table into the body of the mail message, and am failing miserably.

    Problem Part 1:
    I am able to select the table (tblSchedule.Select) but seem unable to copy the table (using oDoc.Selection.Copy following the tblSchedule.Select line). At least, I do not think it is copying the table to the clipboard, as the clipboard is empty when the code is done running. I know the select method is working because the Word document is left open and the table is selected.

    Problem Part 2: Once the table is selected and/or copied, I cannot figure out how to make the table a string (can it be a string?) or an object that can be added to the body of the mail item. Using

    strTable="hi"
    oFinalSchedule.Body=strTable

    I am able to insert "hi" into the body of the message, but I cannot figure out how to replace "strTable" with the selection from Word.

    Any thoughts would be appreciated; thanks in advance for your assistance.

    jen

  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: Copy/paste from Word to Outlook item (vbscript/Office 2k/sr1 (word to

    I think it is going to be difficult to go from a Rich Text environment (Word) to a Rich Text environment (Outlook message in other than plain text format) through a string variable. In fact, I don't think you can do it that way.

    There were some recent discussions of how you could (in a rather involved-sounding way) translate between Rich Text formatting and HTML; this might or might not help you.

    Although it is a terrible kludge, you might just have to use SendKeys to literally paste from the clipboard into your message. I'm not sure why your table is not being copied properly to the clipboard, but one possibility (not sure why you don't get an error) is that there is no Selection property of a document object. You need to get it through the document's ActiveWindow:

    <pre>oDoc.ActiveWindow.Selection.Copy</pre>

    To paste into a MailItem's message area, I generally "send" the key combination for the Subject line (Alt+j) and then a Tab. Your tab order may vary. SendKeys certainly is neither elegant nor 100% reliable, but given the limitations of the Outlook object model, I'm not sure you have much choice here.

    Hope this helps.

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Chicago, Illinois, USA
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copy/paste from Word to Outlook item (vbscript/Office 2k/sr1 (word to

    [edit to fix typo]

    hehehe. Oops...yes, the .copy command works much better with the ActiveWindow in there. I can't believe that.

    I'll play around with SendKeys and see if I can make that work; I can get the cursor to the .body of the document by inserting the other text I need, so maybe I'll add the SendKeys for Ctrl+V at that point. I'll post back with the results.

    This is not going to be a widely-used application (only two or three people) so kludging it is probably okay.

  4. #4
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Chicago, Illinois, USA
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copy/paste from Word to Outlook item (vbscript/Office 2k/sr1 (word to

    I did not end up using SendKeys--after talking to the user, she wanted to be able to control whether or not the selected table was pasted into the Outlook item or not, so I simply copied it and left it on the clipboard for her to do as she pleased.

    Thanks again for the help, though. I have another question about copying/pasting within a document that stems from this that I'll be posting as a new question.

    jen

Posting Permissions

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