Copy Cell Address to clipboard issue - PutInClipboard not working

amarsbar

New Member
Joined
Jan 3, 2017
Messages
2
Hi,

I previously used the following macro to copy a cell address to the clipboard, and subsequently paste elsewhere:

'Public Sub CopySelectionAddressToClipboard()


Dim rngT As Range
Dim strAddress As String
Dim dobClip As DataObject


If Application.Selection.count = 0 Then Exit Sub

Set dobClip = New DataObject
Set rngT = ActiveSheet.Range(Application.Selection.Address)

strAddress = "'" & rngT.Parent.Name & "'!" & rngT.Address

strAddress = Replace(strAddress, "$", "")

dobClip.SetText strAddress
dobClip.PutInClipboard

Set dobClip = Nothing


End Sub'

I have now got a new PC and when I paste what I have copied I get 2 question marks instead of the cell address. I am not sure on how to fix this and any help on this issue would be much appreciated.

I am using windows 10 and excel 2016 (32 bit).

Thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I also had this trouble.
I found that if I had any folder open in "File Explorer" then I am unable to use the "DataObject" to store in clipboard.
Once I've closed "File Explorer" the problem goes away.
Perhaps your solution could be the same ????
I have XL2010 and windows 10
 
Upvote 0
Thank you so much Mick, that has worked for me too. Very odd quirk! I will think of a way to correct this and update this post if I find
 
Upvote 0
Test if this is a workaround...

Code:
[color=darkblue]Sub[/color] CopySelectionAddressToClipboard2()
    [color=green]'late binding to copy text to clipboard.[/color]
    [color=darkblue]If[/color] Application.Selection.Count = 0 [color=darkblue]Then[/color] [color=darkblue]Exit[/color] [color=darkblue]Sub[/color]
    [color=darkblue]With[/color] CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
        .SetText "'" & ActiveSheet.Name & "'!" & Selection.Address(0, 0)
        .PutInClipboard
    [color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
The best way around this that I am aware of is to use Windows API calls instead of the DataObject.
 
Upvote 0
AlphaFrog:-
Unfortunately that also fails !!!!
I would obviously prefer not to have this problem ,but its not too difficult to close a folder!!
 
Last edited:
Upvote 0
Whiskey.
Tango.
Foxtrot.

I spent 20min trying to figure out why the .PutInClipboad was not working today and this is the workaround??? (Shakes Head)
Well now I know.
Microsoft your[sic] the best! 11




I also had this trouble.
I found that if I had any folder open in "File Explorer" then I am unable to use the "DataObject" to store in clipboard.
Once I've closed "File Explorer" the problem goes away.
Perhaps your solution could be the same ????
I have XL2010 and windows 10
 
Upvote 0
The best way around this that I am aware of is to use Windows API calls instead of the DataObject.

Yes agreed, have implemented this approach too, however closing Windows File Explorer does seem to have the suggested approach of allowing the M$ Forms 2.0 approach to actually work! WTF :mad:

For those looking for an API solution that works with Excel 2016 64bit, under win10 x64 this post on SO worked immediately for me when i changed my variable to a string.

https://stackoverflow.com/questions/18668928/excel-2013-64-bit-vba-clipboard-api-doesnt-work

I use the routine to "paste" RangetoHTML code into a populated MailChimp mail-out - my issue NOW is that Outlook 2016 does not display HTML emails correctly :(

Sigh .. Good on ya M$ .. NOT
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,004
Members
452,374
Latest member
keccles

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