PC Review


Reply
Thread Tools Rate Thread

Copy a set bit of text to the clipboard?

 
 
StargateFanNotAtHome
Guest
Posts: n/a
 
      5th Aug 2009
I did a lot of research but haven't found exactly what I need. I
believe syntax is all correct below; so here is what I have so far:

Copying info in a cell:
------------------------
Sub Copy_to_Clipboard_CELL()
'
ActiveSheet.Range("A2").Select
Selection.Copy
End Sub


Copying a range:
---------------
Sub Copy_to_Clipboard_RANGE()
Range("A1:AI35").Select
Selection.Copy
End Sub


But what would be ideal is to just "send" some text to the clipboard,
specifically, the syntax for the hyperlink function. I have a sheet
which is all about tracking URLs and it would be really handy to just
click a button and have that go to the clipboard so it's available for
pasting ('course, a userform where I enter both sides of the info
needed [URL+NAME] for a hyperlink would be better, but I looked at
that earlier today and it's too advanced for me right now <g>). So
copying the syntax to clipboard really great alternative.

The syntax I'd like to send is this, pretty standard stuff:

=HYPERLINK(" URL ", " name ")

Thanks! D
 
Reply With Quote
 
 
 
 
StargateFanNotAtHome
Guest
Posts: n/a
 
      5th Aug 2009
Oh, this is great. I found something neat completely by accident. I
had copy-pasted the code of one URL into a new cell and then delete
both the URL and the name from between the quotation marks and the
text disappeared from view. Yet when I activated that cell, the code
was there. So all I have to do is to copy down the code throughout
the sheet and I'll be set.

However, after finding this issue with the clipboard, would still like
to know how to do the above, if I may ... my clipboard vb syntax is
not complete, I feel, without it.

Thank you! D
 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      6th Aug 2009
You can put any text you want on the clipboard, and retrieve text from
the clipboard, with code like:

Sub PutOnClipboard(Text As String)
Dim DataObj As New MSForms.DataObject
DataObj.SetText Text
DataObj.PutInClipboard
End Sub

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

You'll need to set a Reference to the MSForm library. The easiest way
to do this is simply insert a UserForm into the project. That will set
up reference automatically.

You can then use the code above as shown below:

Dim S As String
PutOnClipboard "hello world"
S = GetFromClipboard()
Debug.Print S

See http://www.cpearson.com/Excel/clipboard.aspx for additional
information and example code for working with the clipboard.

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





On Wed, 5 Aug 2009 14:52:57 -0700 (PDT), StargateFanNotAtHome
<(E-Mail Removed)> wrote:

>I did a lot of research but haven't found exactly what I need. I
>believe syntax is all correct below; so here is what I have so far:
>
>Copying info in a cell:
>------------------------
>Sub Copy_to_Clipboard_CELL()
>'
>ActiveSheet.Range("A2").Select
> Selection.Copy
>End Sub
>
>
>Copying a range:
>---------------
>Sub Copy_to_Clipboard_RANGE()
> Range("A1:AI35").Select
> Selection.Copy
>End Sub
>
>
>But what would be ideal is to just "send" some text to the clipboard,
>specifically, the syntax for the hyperlink function. I have a sheet
>which is all about tracking URLs and it would be really handy to just
>click a button and have that go to the clipboard so it's available for
>pasting ('course, a userform where I enter both sides of the info
>needed [URL+NAME] for a hyperlink would be better, but I looked at
>that earlier today and it's too advanced for me right now <g>). So
>copying the syntax to clipboard really great alternative.
>
>The syntax I'd like to send is this, pretty standard stuff:
>
>=HYPERLINK(" URL ", " name ")
>
>Thanks! D

 
Reply With Quote
 
StargateFan
Guest
Posts: n/a
 
      10th Aug 2009
On Wed, 05 Aug 2009 19:01:33 -0400, Chip Pearson <(E-Mail Removed)>
wrote:

>You can put any text you want on the clipboard, and retrieve text from
>the clipboard, with code like:
>
>Sub PutOnClipboard(Text As String)
> Dim DataObj As New MSForms.DataObject
> DataObj.SetText Text
> DataObj.PutInClipboard
>End Sub
>
>Function GetFromClipboard() As String
> Dim DataObj As New MSForms.DataObject
> DataObj.GetFromClipboard
> GetFromClipboard = DataObj.GetText
>End Function
>
>You'll need to set a Reference to the MSForm library. The easiest way
>to do this is simply insert a UserForm into the project. That will set
>up reference automatically.
>
>You can then use the code above as shown below:
>
>Dim S As String
>PutOnClipboard "hello world"
>S = GetFromClipboard()
>Debug.Print S
>
>See http://www.cpearson.com/Excel/clipboard.aspx for additional
>information and example code for working with the clipboard.


Thanks for this reference. I saw a few messages that mentioned some
of the above but it's nice to get it all spelled out since the
messages I read were written by people who seemd to know what they're
doing and not newbies.

<sigh> It seems rather complicated, so I'll have to study this. Once
I master it, I'm sure it'll be easy, it's just getting there <g>. But
this makes it a lot easier.

Thanks! D

>Cordially,
>Chip Pearson
>Microsoft Most Valuable Professional
> Excel Product Group
>Pearson Software Consulting, LLC
>www.cpearson.com
>(email on web site)
>
>
>
>
>
>On Wed, 5 Aug 2009 14:52:57 -0700 (PDT), StargateFanNotAtHome
><(E-Mail Removed)> wrote:
>
>>I did a lot of research but haven't found exactly what I need. I
>>believe syntax is all correct below; so here is what I have so far:
>>
>>Copying info in a cell:
>>------------------------
>>Sub Copy_to_Clipboard_CELL()
>>'
>>ActiveSheet.Range("A2").Select
>> Selection.Copy
>>End Sub
>>
>>
>>Copying a range:
>>---------------
>>Sub Copy_to_Clipboard_RANGE()
>> Range("A1:AI35").Select
>> Selection.Copy
>>End Sub
>>
>>
>>But what would be ideal is to just "send" some text to the clipboard,
>>specifically, the syntax for the hyperlink function. I have a sheet
>>which is all about tracking URLs and it would be really handy to just
>>click a button and have that go to the clipboard so it's available for
>>pasting ('course, a userform where I enter both sides of the info
>>needed [URL+NAME] for a hyperlink would be better, but I looked at
>>that earlier today and it's too advanced for me right now <g>). So
>>copying the syntax to clipboard really great alternative.
>>
>>The syntax I'd like to send is this, pretty standard stuff:
>>
>>=HYPERLINK(" URL ", " name ")
>>
>>Thanks! D


 
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:50 PM.