• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy sometext to clipboard using VBA

Debraj

Excel Ninja
Hi,

I have list of data in a sheet.

How to copy some text in clipboard using VBA.


I have created a SQL query i.e select ... where EmpCode in ('list of unique data using VBA and concat')...

Everything is going smoothly, but i am unable to copy the msg (a rally BIG String Variable) to the Clipboard, so that user dont have to select the textbox, and then CTRL+A , and then hit CTRL+C.

just hit the COPY button, and textbox1.text will goes to clipboard and me.unload..


Please Help
 
Hi Roy ,


Can you provide more details ? How big is the message ( number of characters ) ? What error message , if any , do you get when you try to copy your message to the clipboard ? How are you executing the copy at present ?


Narayan
 
Hi Debraj Roy,

First, set a reference to Microsoft Forms 2.0 Object Library (will already be selected if you have a userform).

[pre]
Code:
Sub CopytoClip ()

Dim dClip As DataObject
Dim sSQL as String

Set dClip = New DataObject
sSQL = "list of unique data using VBA and concat"
dClip.SetText sSQL
dClip.PutInClipboard
ActiveSheet.PasteSpecial "Unicode Text"
End Sub
[/pre]
 
Back
Top