Copy items from Clipboard

JohnRyan

New Member
Joined
Jan 4, 2014
Messages
9
I have 2 items copied to the Clipboard in XL
I need a Macro to Paste item 1 to Sheet1, item 2 to Sheet2
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

JohnRyan

New Member
Joined
Jan 4, 2014
Messages
9
Hi Oldbrewer,

Thank you for your reply. I manually pasted item 1 to Sheet1 and item 2 to Sheet2 and recorded the Macro.

When I run the macro :-

Sub Macro1()

ActiveSheet.Paste
Sheets("Sheet2").Select
ActiveSheet.Paste

End Sub


It pastes item one into both sheets
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,779
Office Version
  1. 2010
Platform
  1. Windows
You would need to paste from the Office clipboard, not the Excel clipboard. That's much more complicated, and would require some Windows API.
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,910

ADVERTISEMENT

How did those "two items" get pasted into the clipboard.
What are they? Strings?

What does this return
Code:
Sub test()
    Dim myDO As New DataObject

    With myDO
        .GetFromClipboard
        MsgBox .GetText()
    End With
End Sub
 

JohnRyan

New Member
Joined
Jan 4, 2014
Messages
9
Hi, mikerickson

I copied them separately into the clipboard using Right Mouse Clicks.
I tried Strings first - first item = "a" and second item = "b".
Then I tried integers - first item = 1 & second item = 2.


Your macro above gave the following message when I tried to run it :-

Compile error:
User-defined type not identified
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,779
Office Version
  1. 2010
Platform
  1. Windows

ADVERTISEMENT

Mike's code requires that you set a reference to Microsoft Forms Object Library. Ot you could use this:

Code:
Sub test()
    With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
        .GetFromClipboard
        MsgBox .GetText()
    End With
End Sub
 

JohnRyan

New Member
Joined
Jan 4, 2014
Messages
9
Dear SHG, when I run your code above it displays a Microsoft Excel Box showing the latest item from the clipboard, provided it’s not data from Excel

When I try to paste data from Excel I get the following Error message
Data Object GetText invalid FORMATETC structure
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,779
Office Version
  1. 2010
Platform
  1. Windows
Right; see post#4. You need to get data from the Office clipboard, not the Excel clipboard.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,672
Messages
5,597,488
Members
414,146
Latest member
marginmakerb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top