Copy a cell to the clipboard: simple macro stopped working

terrypin

New Member
Joined
Dec 3, 2016
Messages
25
I can't recall where I pasted it from last year, possibly here, but the macro below used to work sweetly. However it now fails consistently, placing '??' on the clipboard instead of the text in cell B3.

Code:
<code>Sub CopyTrackDescrToClipbrd()
' Copies text contents of B3 in active TrackDataSheet to clipboard
' Remains on clipboard after macro finishes
Dim MyData
Set MyData = New DataObject
MyData.SetText Range("B3")
MyData.PutInClipboard
End Sub</code>

Elsewhere I read this: "There is a known bug in the Dataobject if you are using Windows 8 or later. It is safer to use Windows API calls for copying text from the clipboard."
But, as a VBA novice and non-programmer, I don't know how to do that.

I've done quite a lot of searching and am surprised I've so far not found a simple (reliable) piece of code to do such a commonplace task as copy a cell to the Windows clipboard!

Terry, East Grinstead, UK
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Ref:- later versions of Office/windows:-
If you have "File Explorer" or possibly other applications OPEN this is what happens with "DataObjects"!!!!
 
Upvote 0
Please read and comply with the forum rules on cross-posting. This is not the first time, so please make sure it's the last time you need to be reminded. ;)
 
Upvote 0
Ref:- later versions of Office/windows:-
If you have "File Explorer" or possibly other applications OPEN this is what happens with "DataObjects"!!!!

Thanks. Sounds a severe limitation then! Is there a suggested solution?

Terry, East Grinstead, UK
 
Upvote 0
Well, this was not really what I understand as a cross-post! It was a follow-on from the one I made two days ago in the Excel Forum.
https://www.excelforum.com/excel-pr...tents-to-clipboard-now-fails.html#post4915059

As you see, I've failed so far to get a solution there. So I came here, adding more information, and hoping to make further progress.

And I'll probably pursue the problem elsewhere too.

If that puts subscribers off trying to help, so be it.

Terry, East Grinstead, UK
 
Upvote 0
A cross-post is simply posting the same question in more than one forum. The forum rules explain why we ask you to provide links so, should you pursue it on other forums too, we'd expect links to those posts as well as a courtesy.
 
Upvote 0
Solution by xlnitwit in post #12 of the earlier thread. My working code is now:
Code:
Sub CopyTrackDescrToClipbrd()
' Copies contents of B3 in active TrackDataSheet to clipboard
' Remains on clipboard after macro finishes
    Range("B3").Copy
End Sub

Terry, East Grinstead, UK
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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
Back
Top