Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Feb 2004
    Location
    Seattle, Washington, USA
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What's wrong with this macro? (Word 2003)

    I recorded a macro to paste unformatted from the clipboard and the macro reads:

    Selection.PasteAndFormat (wdPasteDefault)

    While recording, I specifically selected Paste Special, followed by Unformatted Text. When executed, the macro pastes but does not paste unformatted. It takes on the formatting of what it copied. Can someone give me a simple correction?

    Thanks,
    Bob in Seattle

  2. #2
    Platinum Lounger
    Join Date
    Jan 2001
    Posts
    3,788
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: What's wrong with this macro? (Word 2003)

    Hi Bob

    Change it to:

    <code>Selection.PasteAndFormat (wdFormatPlainText)</code>

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: What's wrong with this macro? (Word 2003)

    Selection.PasteSpecial DataType:=wdPasteText

    In cases like these, you can easily find out what to do:
    - In the Visual Basic Editor, type Selection followed by a period.
    - IntelliSense will kick in and display a list of available properties and methods.
    - One of them is the one you want, PasteSpecial; select it and press Tab.
    - Now press F1 to get online help.

  4. #4
    New Lounger
    Join Date
    Feb 2004
    Location
    Seattle, Washington, USA
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What's wrong with this macro? (Word 2003)

    Thank you, Tony and Hans! The revised macro works like a charm. Wonder why it didn't record properly to begin with.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: What's wrong with this macro? (Word 2003)

    The macro recorder does a creditable job in general, but it is far from perfect, and in some case its results are awkward, inefficient or even plainly wrong.

  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: What's wrong with this macro? (Word 2003)

    Looking at VBA's help for the PasteAndFormat method it keeps referring to pasting "selected table cells." I have never seen this recorded in a macro before, and I wonder whether you might have had a table in the clipboard and this caused Word to record PasteAndFormat rather than PasteSpecial? When I test that theory in Word 2002, I get exactly the original code you posted. Very illogical, when one has chosen "unformatted"!

  7. #7
    New Lounger
    Join Date
    Feb 2004
    Location
    Seattle, Washington, USA
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What's wrong with this macro? (Word 2003)

    I even tried the macro record feature an additional time and came up with the same original code. No, I was not in a table when I copied the text. Very strange.

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What's wrong with this macro? (Word 2003)


Posting Permissions

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