+ Reply to Thread
Results 1 to 7 of 7

Pasting range from clipboard

  1. #1
    Registered User
    Join Date
    03-13-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    7

    Pasting range from clipboard

    Hi all,

    This seems really simple but I've spent hours searching the forums without success. I'm writing a subroutine where the user copies data (multiple rows and columns of values) to the clipboard (control c) from another Excel document and then presses a form control button. This starts a macro, which begins by pasting the data in to a blank sheet. I cannot get this to work.

    Pasting the data manually (control V) to cell A1 on the sheet works fine, but just copying what the macro recorder shows (see below) yields the error 'Paste method of Worksheet class has failed'. I've tried too many codes to display them all here, but surely this is simple?

    Please Login or Register  to view this content.
    Many thanks for your help!
    Matt

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Pasting range from clipboard

    why not a macro for selecting desired range, opening another document and pasting directly ?
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    03-13-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Pasting range from clipboard

    The source document always has a different filename, and the range is always different. It's easy for the user to copy it to clipboard but a macro finding the desired range would be complicated (especially as the source document could change formatting)

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Pasting range from clipboard

    try this code
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-13-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Pasting range from clipboard

    Thanks patel,

    Unfortunately I get a 'Get text invalid format structure' error on the line S = DataObj.GetText. I should note that my data is all numbers,

  6. #6
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Pasting range from clipboard

    try this attachment
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    03-13-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Pasting range from clipboard

    Thanks a lot Patel, that works! I've just got to try and understand why now.

+ 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