PC Review


Reply
Thread Tools Rate Thread

Copy contents of variable into clipboard

 
 
Simka
Guest
Posts: n/a
 
      28th Oct 2008
Hi everyone,

My head has gone blank. I am trying to copy the contents of a variable into
the clipboard.

ie:
value in clipboard = MyVariable

Can someone please remind me?

 
Reply With Quote
 
 
 
 
Wigi
Guest
Posts: n/a
 
      28th Oct 2008
What do you intend to do with the variable?

Wouldn't there be better methods to use, then?

--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"Simka" wrote:

> Hi everyone,
>
> My head has gone blank. I am trying to copy the contents of a variable into
> the clipboard.
>
> ie:
> value in clipboard = MyVariable
>
> Can someone please remind me?
>

 
Reply With Quote
 
ron
Guest
Posts: n/a
 
      28th Oct 2008
On Oct 28, 10:59*am, Simka <Si...@discussions.microsoft.com> wrote:
> Hi everyone,
>
> My head has gone blank. I am trying to copy the contents of a variable into
> the clipboard.
>
> ie:
> value in clipboard = MyVariable
>
> Can someone please remind me?


Try the following...ron

Dim mystring As New DataObject

my_var= "assign something to the variable"

mystring.SetText my_var
mystring.PutInClipboard
ActiveSheet.PasteSpecial Format:="Text"
 
Reply With Quote
 
Simka
Guest
Posts: n/a
 
      29th Oct 2008
It's basically a follow-on from these statements:

Sub Simka1()
'This routine adds the values of selected cells and
'places the result in cell A5000 then copies the value to clipboard.

With Range("A5000")

.Value = Application.WorksheetFunction.Sum(Selection)
.Copy

End With
End Sub

and

Sub Simka2()

'This routine adds the values of selected cells and
'places the result in the variable 'SumOfRange'.

Dim SumOfRange As Double

SumOfRange = 0

SumOfRange = Application.WorksheetFunction.Sum(Selection) 'Add the Range

Debug.Print SumOfRange 'Check result in Immediate window

End Sub

Where routine Simka1 places the value into cell A5000 and then copies the
value into the clipboard, this is the long run makes the worksheet size
(file) much bigger.

Routine Simka2 does much the same thing except it places the value in the
variable SumOfRange so that I could then use a different routine to place
that value later.

I want a mixture of the two. I want routine Simka2 but then place the value
into the clipboard ready for pasting elsewhere. So I am after something like:

Sub Simka2()
Dim SumOfRange As Double
SumOfRange = 0
SumOfRange = Application.WorksheetFunction.Sum(Selection) 'Add the Range

Value in Clipboard = SumOfRange

Debug.Print SumOfRange 'Check result in Immediate window
End Sub



"Wigi" wrote:

> What do you intend to do with the variable?
>
> Wouldn't there be better methods to use, then?
>
> --
> Wigi
> http://www.wimgielis.be = Excel/VBA, soccer and music
>
>
> "Simka" wrote:
>
> > Hi everyone,
> >
> > My head has gone blank. I am trying to copy the contents of a variable into
> > the clipboard.
> >
> > ie:
> > value in clipboard = MyVariable
> >
> > Can someone please remind me?
> >

 
Reply With Quote
 
Simka
Guest
Posts: n/a
 
      29th Oct 2008
Hi ron,

I'm not sure how to understand what you have written below, but I think you
are on the right lines and understanding what I am trying to achieve.

I'm not too familiar with Class Modules, I find them a little confusing. Can
you write the code in full so that I can copy it to modules/class modules and
then I can follow what you are thinking?

Cheers,

Simka.


"ron" wrote:

> On Oct 28, 10:59 am, Simka <Si...@discussions.microsoft.com> wrote:
> > Hi everyone,
> >
> > My head has gone blank. I am trying to copy the contents of a variable into
> > the clipboard.
> >
> > ie:
> > value in clipboard = MyVariable
> >
> > Can someone please remind me?

>
> Try the following...ron
>
> Dim mystring As New DataObject
>
> my_var= "assign something to the variable"
>
> mystring.SetText my_var
> mystring.PutInClipboard
> ActiveSheet.PasteSpecial Format:="Text"
>

 
Reply With Quote
 
ron
Guest
Posts: n/a
 
      29th Oct 2008
On Oct 29, 8:40*am, Simka <Si...@discussions.microsoft.com> wrote:
> Hi ron,
>
> I'm not sure how to understand what you have written below, but I think you
> are on the right lines and understanding what I am trying to achieve.
>
> I'm not too familiar with Class Modules, I find them a little confusing. Can
> you write the code in full so that I can copy it to modules/class modulesand
> then I can follow what you are thinking?
>
> Cheers,
>
> Simka.
>
>
>
> "ron" wrote:
> > On Oct 28, 10:59 am, Simka <Si...@discussions.microsoft.com> wrote:
> > > Hi everyone,

>
> > > My head has gone blank. I am trying to copy the contents of a variable into
> > > the clipboard.

>
> > > ie:
> > > value in clipboard = MyVariable

>
> > > Can someone please remind me?

>
> > Try the following...ron

>
> > * * Dim mystring As New DataObject

>
> > * * my_var= "assign something to the variable"

>
> > * * mystring.SetText my_var
> > * * mystring.PutInClipboard
> > * * ActiveSheet.PasteSpecial Format:="Text"- Hide quoted text -

>
> - Show quoted text -


Hi Simka...Just copy and paste the following code into a module.
Assign whatever it is that you want to move to the clipboard to
"my_var". The ActiveSheet.Paste line simply demonstrates that you
have copied the information to the clipboard. Change or delete this
line depending on what you want to do with the information once it is
in the clipboard...ron

Sub CopyToClipboard()

Dim mystring As New DataObject

my_var = "assign something to the variable"

mystring.SetText my_var
mystring.PutInClipboard

ActiveSheet.PasteSpecial Format:="Text"

End Sub
 
Reply With Quote
 
Simka
Guest
Posts: n/a
 
      29th Oct 2008


"ron" wrote:

> On Oct 29, 8:40 am, Simka <Si...@discussions.microsoft.com> wrote:
> > Hi ron,
> >
> > I'm not sure how to understand what you have written below, but I think you
> > are on the right lines and understanding what I am trying to achieve.
> >
> > I'm not too familiar with Class Modules, I find them a little confusing. Can
> > you write the code in full so that I can copy it to modules/class modules and
> > then I can follow what you are thinking?
> >
> > Cheers,
> >
> > Simka.
> >
> >
> >
> > "ron" wrote:
> > > On Oct 28, 10:59 am, Simka <Si...@discussions.microsoft.com> wrote:
> > > > Hi everyone,

> >
> > > > My head has gone blank. I am trying to copy the contents of a variable into
> > > > the clipboard.

> >
> > > > ie:
> > > > value in clipboard = MyVariable

> >
> > > > Can someone please remind me?

> >
> > > Try the following...ron

> >
> > > Dim mystring As New DataObject

> >
> > > my_var= "assign something to the variable"

> >
> > > mystring.SetText my_var
> > > mystring.PutInClipboard
> > > ActiveSheet.PasteSpecial Format:="Text"- Hide quoted text -

> >
> > - Show quoted text -

>
> Hi Simka...Just copy and paste the following code into a module.
> Assign whatever it is that you want to move to the clipboard to
> "my_var". The ActiveSheet.Paste line simply demonstrates that you
> have copied the information to the clipboard. Change or delete this
> line depending on what you want to do with the information once it is
> in the clipboard...ron
>
> Sub CopyToClipboard()
>
> Dim mystring As New DataObject
>
> my_var = "assign something to the variable"
>
> mystring.SetText my_var
> mystring.PutInClipboard
>
> ActiveSheet.PasteSpecial Format:="Text"
>
> End Sub
>


Hi ron,

Ah-ha, this is better. this is what I'm nearly trying to get to. I vaguely
seem to remember years ago I had the same sort of problem but I used a
totally different approach, maybe one day I'll remember how I did it.

Anyway I've slightly adjusted your code to accommodate my needs.

Have a look at my reply to Wigi, this may help you understand more or less
what I was trying to achieve. This was so that I could select a number of
different cells (with values), add all the values and and hold the result in
a variable for later use and I also wanted to hold the result in the
clipboard instead of placing the result in a cell.

Cheers & thanks,

Simka.

 
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
Copy all contents of a recordset to clipboard =?Utf-8?B?TWlrZQ==?= Microsoft Access Form Coding 6 10th Jan 2007 08:44 PM
Variable for clipboard contents? Zarbol Tsar Windows XP General 1 16th Dec 2004 02:32 PM
Set variable to clipboard contents? Fred Smith Microsoft Excel Programming 2 5th Sep 2004 08:23 PM
copy var contents to the clipboard Stephen Russell Microsoft C# .NET 3 3rd Feb 2004 05:32 PM
copy string variable contents to clipboard Ted Microsoft Access VBA Modules 3 31st Dec 2003 08:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:02 AM.