+ Reply to Thread
Results 1 to 7 of 7

Clipboard for copied range

  1. #1
    Forum Contributor
    Join Date
    01-22-2022
    Location
    UK
    MS-Off Ver
    365
    Posts
    125

    Clipboard for copied range

    I wanted to copy data onto the clipboard, so that it can be pasted into another application.
    The pasted data will be transposed though.

    I thought it could be done with an array.
    The question is: If you take data, put it in an array, rearrange the array, can it be put into the clipboard so it can be pasted into another application?

    The code below is for info only, so far I create another sheet and paste data in there, then copy again to clipboard.


    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Clipboard for copied range

    Hello. Look at the following code:

    Please Login or Register  to view this content.
    As the name implies, the above does a Copy without Paste (ie: Ctrl+C).

    So you have to do the Ctrl+V "by hand" in that other application you didn't give more details about.

  3. #3
    Forum Contributor
    Join Date
    01-22-2022
    Location
    UK
    MS-Off Ver
    365
    Posts
    125

    Re: Clipboard for copied range

    Thanks for providing the code.
    It looks like a new workbook is opened in the background.

    With the array that I had, I was I was going to create another 2 arrays, based on the first array.
    But this would have been in VBA so it's not seen in Excel.
    Then place the 2D range in the clipboard.
    It could be done by pasting into the new workbook temporarily, as per your code I think.

    Do you think that 2D arrays can be placed in the clipboard, like the COPY command in Excel?

    Otherwise thanks for the solution.

    Attachment 801261

  4. #4
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Clipboard for copied range

    That is what the provided code is doing.

    For example:
    > Select any range.
    > Run the macro
    > And when finished go to another application (Word, for example) and there do Ctrl+V (Paste)...

    And regarding your link I get the following:

    ---> Invalid attachment specified.

  5. #5
    Forum Contributor
    Join Date
    01-22-2022
    Location
    UK
    MS-Off Ver
    365
    Posts
    125

    Re: Clipboard for copied range

    OK thanks.
    Regarding the link, I don't know why it does that. It was a snapshot to show a 2D range/2D array.

    So we know that an Excel range can be placed on the clipboard, but could an array be placed on the clipboard.

  6. #6
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Clipboard for copied range

    In VBA there is an object that connects to the clipboard called a DataObject. It allows you to send or receive data:

    PHP Code: 
    Sub Macro1()
    Dim objDataObject
    Set objDataObject 
    CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

    objDataObject.SetText "Hello."
    objDataObject.PutInClipboard
    End Sub

    Rem o0o
    -o0o

    Sub Macro2
    ()
    Dim objDataObject
    Set objDataObject 
    CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

    objDataObject.GetFromClipboard
    Range
    ("A1") = objDataObject.GetText
    End Sub 
    The limitation of this is that it only works with texts.
    Last edited by beyond Excel; 10-19-2022 at 01:07 PM.

  7. #7
    Forum Contributor
    Join Date
    01-22-2022
    Location
    UK
    MS-Off Ver
    365
    Posts
    125

    Re: Clipboard for copied range

    OK, thanks for looking into beyond Excel.
    Couldn't get it to work but I can do more research on the DataObject.

+ 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. rows not copied to clipboard with COPY method
    By vba_php in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2020, 01:15 AM
  2. Clearing a copied Shape from the Clipboard with VBA?
    By aquixano in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-06-2016, 08:37 AM
  3. Replies: 3
    Last Post: 07-11-2015, 05:17 PM
  4. Macro validate string copied to Clipboard
    By petreli in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-17-2012, 05:51 AM
  5. Is it possible to paste the first item that you copied in the clipboard??
    By mageamida in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-30-2012, 12:52 PM
  6. Store copied data into Variable as a value from clipboard
    By Saurabh guddu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2012, 04:28 AM
  7. How do I display copied autoshapes completely in clipboard
    By Biscuit Maker in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 05-31-2006, 10:20 AM

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