ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy contents of variable into clipboard (https://www.excelbanter.com/excel-programming/419169-copy-contents-variable-into-clipboard.html)

Simka

Copy contents of variable into clipboard
 
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?


Wigi

Copy contents of variable into clipboard
 
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?


ron

Copy contents of variable into clipboard
 
On Oct 28, 10:59*am, 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?


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"

Simka

Copy the contents of variable into clipboard
 
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 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"


ron

Copy the contents of variable into clipboard
 
On Oct 29, 8:40*am, Simka 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 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

Simka

Copy the contents of variable into clipboard
 


"ron" wrote:

On Oct 29, 8:40 am, Simka 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 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.



All times are GMT +1. The time now is 08:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com