+ Reply to Thread
Results 1 to 8 of 8

Paste unformatted text into Word via Excel

  1. #1
    Registered User
    Join Date
    03-13-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    15

    Paste unformatted text into Word via Excel

    I'm new to VBA. I'm trying to take an excel range and paste it as unformatted text into Word. The problem is I can't figure out how to paste as unformatted text specifically. Everything else works fine.
    Please Login or Register  to view this content.
    Running this says "Compile Error: variable not defined." with wdPasteText highlighted. I tried pasting this way in word and it WORKS, but not in excel

    All my code works if I replace the paste line with
    Please Login or Register  to view this content.
    But this isn't what I want since it pastes everything as a table.

    Any ideas?

    Thanks

    EDIT: I should probably mention I'm using Office 2010 Beta :o
    Last edited by iamtehwalrus; 04-07-2010 at 01:21 AM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Paste unformatted text into Word via Excel

    Try

    Please Login or Register  to view this content.

    "wdPasteText" is a word constant not an excel one, that is why you get a compiler error.

    Hope this helps, I'm not up on word
    Last edited by Marcol; 04-07-2010 at 12:34 AM.

  3. #3
    Registered User
    Join Date
    03-13-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Paste unformatted text into Word via Excel

    Run-time error '448':
    Named argument not found

    sosad
    Last edited by teylyn; 04-07-2010 at 12:47 AM.

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Paste unformatted text into Word via Excel

    iamthewalrus, please don't quote whole posts.

  5. #5
    Registered User
    Join Date
    03-13-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Paste unformatted text into Word via Excel

    Sorry, I did it out of habit

    And I fixed my problem. I went into word and made this macro
    Please Login or Register  to view this content.
    and '2' popped up, so I just replaced wdPasteText with 2 in my original code

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Paste unformatted text into Word via Excel

    Okay, I was wrong to suggest using "Paste:=xlPasteValues"

    It seems when you paste to Word a shape not a table is the result, it looks like a table but it's not,

    I tried

    Please Login or Register  to view this content.
    that also failed.

    And as I ventured into my next theory, you solved it yourself, well done!

    Nice one, I'll remember that!

    Regards
    Alistair

  7. #7
    Registered User
    Join Date
    03-13-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Paste unformatted text into Word via Excel

    Yeah, unfortunately it's just a makeshift workaround. Definitely not ideal. I'm not entirely sure what's going on, but I'm assuming Excel doesn't have access to those Word constants (which is why they start with wd). There's probably some way to fix that but I don't know what that is

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Paste unformatted text into Word via Excel

    Don't know if there will be, You have probably found the only way.

    Here is a list of all the constants. (You could "tell" Excel the values, as below)
    Please Login or Register  to view this content.
    wdPasteDefault depends on what is on the clipboard

    This is probably why it pastes a shape not a table when copying Excel cells if it dosn't know what the constant is.

    Why wdPasteOLEObject is also 0, I don't know.
    Don't know what happened to 6

    Cheers.....
    Last edited by Marcol; 04-07-2010 at 04:10 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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