+ Reply to Thread
Results 1 to 7 of 7

VBA to copy selected text from outlook item to existing word doc

  1. #1
    Registered User
    Join Date
    08-29-2012
    Location
    South Yorks, England
    MS-Off Ver
    Excel 2010
    Posts
    32

    VBA to copy selected text from outlook item to existing word doc

    I have been trying to create a macro in outlook which copies the previously selected part of an email and pastes it onto an existing word template. The code I have created gives me "object variable or with block variable not set"
    HTML Code: 
    Which object do I need to set?

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA to copy selected text from outlook item to existing word doc

    Which selection are you referring to? Outlook or Word? So, you have to specify.
    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    08-29-2012
    Location
    South Yorks, England
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: VBA to copy selected text from outlook item to existing word doc

    Thanks Tinbendr - I have added objWord to that last line and it now works in that it pastes the clipboard contents. However, now I can't get it to copy to clipboard, I get "Object doesn't support this property or method" error on
    HTML Code: 
    . Researching other blogs, it seems I need to use DataObject but I can't find how to define this. Should I post this as a separate question or keep it altogether?
    Last edited by bensox; 02-14-2014 at 05:21 AM.

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA to copy selected text from outlook item to existing word doc

    Here is an excellent article about clipboard in VBA.

    After some searching, apparently you can't get the selected text in a preview window. However, I was able to get selected text in activewindow.

    You'll have to have the MSForms reference set in Excel. to use DataObj.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-29-2012
    Location
    South Yorks, England
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: VBA to copy selected text from outlook item to existing word doc

    Tinbendr, I get "Compile error: Expected variable or procedure, not project" at
    Please Login or Register  to view this content.
    when I run the code you provided. I read the article you point to and also http://http://www.excelforum.com/exc...ataobject.html, which helped me find that I did indeed have MSForms listed. But adding an explicit reference didn't change anything. Appreciate your help, I think we're very near the solution now.

  6. #6
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA to copy selected text from outlook item to existing word doc

    I thought you might. /:|

    Outlook certainly isn't my forte`.

    This was the only way i could get it to work.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-29-2012
    Location
    South Yorks, England
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: VBA to copy selected text from outlook item to existing word doc

    Yes, adding your extra code to it worked, however I will have to play around a bit more as the email messages in questions have the text split up in a table style format and the macro only copies the first part of that which is selected. Thank you for getting me this far though!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Getting value of selected item within a ComboBox ~ Microsoft Word
    By iestyn02 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-02-2013, 09:27 AM
  2. Replies: 0
    Last Post: 07-03-2012, 01:06 AM
  3. copy data from selected cells , in selected row and paste it to ms word table ?
    By aaashaaa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-06-2010, 03:25 PM
  4. How to copy selected listbox item to sheet
    By michdan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-14-2005, 08:05 AM
  5. How do I tell Excel to take a selected item and copy it to anothe.
    By HEATHERCOX in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-28-2005, 12:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1