PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

copy text to clipboard

 
 
Mitch Powell
Guest
Posts: n/a
 
      27th Aug 2009
I need to copy some text to the clipboard using vba so that is will be
available in another application. For various reasons, I cannot use the
native Excel Copy function in this case. I can find no way to do this.
Surely I am missing something obvious.
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      27th Aug 2009
In VBA, go to the Tools menu, choose References, and put a check next
to "Microsoft Forms 2.0 Object Library" (or, just add a UserForm to
the project and then delete the UserForm). Then, use code like


Sub PutToClipboard(S As String)
Dim DataObj As New MSForms.DataObject
DataObj.SetText S
DataObj.PutInClipboard
End Sub

Function GetFromClipboard()
Dim DataObj As New MSForms.DataObject
DataObj.GetFromClipboard
GetFromClipboard = DataObj.GetText
End Function

You would then use these functions like

Sub AAA()
Dim S As String
PutToClipboard "hello"
S = GetFromClipboard
MsgBox S
End Sub

See http://www.cpearson.com/excel/Clipboard.aspx for more details.


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Thu, 27 Aug 2009 05:57:01 -0700, Mitch Powell
<(E-Mail Removed)> wrote:

>I need to copy some text to the clipboard using vba so that is will be
>available in another application. For various reasons, I cannot use the
>native Excel Copy function in this case. I can find no way to do this.
>Surely I am missing something obvious.

 
Reply With Quote
 
Mitch Powell
Guest
Posts: n/a
 
      28th Aug 2009
Perfect. Thank you very much!

"Chip Pearson" wrote:

> In VBA, go to the Tools menu, choose References, and put a check next
> to "Microsoft Forms 2.0 Object Library" (or, just add a UserForm to
> the project and then delete the UserForm). Then, use code like
>
>
> Sub PutToClipboard(S As String)
> Dim DataObj As New MSForms.DataObject
> DataObj.SetText S
> DataObj.PutInClipboard
> End Sub
>
> Function GetFromClipboard()
> Dim DataObj As New MSForms.DataObject
> DataObj.GetFromClipboard
> GetFromClipboard = DataObj.GetText
> End Function
>
> You would then use these functions like
>
> Sub AAA()
> Dim S As String
> PutToClipboard "hello"
> S = GetFromClipboard
> MsgBox S
> End Sub
>
> See http://www.cpearson.com/excel/Clipboard.aspx for more details.
>
>
> Cordially,
> Chip Pearson
> Microsoft Most Valuable Professional
> Excel Product Group, 1998 - 2009
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email on web site)
>
>
>
> On Thu, 27 Aug 2009 05:57:01 -0700, Mitch Powell
> <(E-Mail Removed)> wrote:
>
> >I need to copy some text to the clipboard using vba so that is will be
> >available in another application. For various reasons, I cannot use the
> >native Excel Copy function in this case. I can find no way to do this.
> >Surely I am missing something obvious.

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clipboard gets empty by itself, cleared clipboard, copy paste doesn't work, outlook clears clipboard, problems with clipboard - possible solution Jens Hoerburger Microsoft Outlook 0 24th Aug 2006 02:44 PM
How copy ONLY text to clipboard? RandyDtg1 Microsoft Powerpoint 2 11th Jun 2004 01:41 AM
Re: How can I copy text to clipboard using VB? John Nurick Microsoft Access VBA Modules 7 3rd Apr 2004 08:03 AM
How can I copy text to clipboard using VB? Ted Allen Microsoft Access VBA Modules 0 30th Mar 2004 10:03 PM
Req: Copy text from jpg to clipboard ms Freeware 4 23rd Nov 2003 07:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:57 PM.