Copy&Paste and store for later

M

MG

I got a Word Macro that Copy & Paste several values
between 2 docs.
What I need is to store in a variable a particular value
I'm copying from a cell of a table with the command:

Selection.SelectCell
Selection.Copy

so that I can use this value later.
How can I "paste" or store what is in the clipboard into a
variable?
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < MG > écrivait :
In this message, < MG > wrote:

|| I got a Word Macro that Copy & Paste several values
|| between 2 docs.
|| What I need is to store in a variable a particular value
|| I'm copying from a cell of a table with the command:
||
|| Selection.SelectCell
|| Selection.Copy
||
|| so that I can use this value later.
|| How can I "paste" or store what is in the clipboard into a
|| variable?

Is the selection straight text, or is there formatting and/or objects as
well?
Will the source document be closed before you need to recall the stored
selections?
What Word version?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

Guest

|| I got a Word Macro that Copy & Paste several values
|| between 2 docs.
|| What I need is to store in a variable a particular value
|| I'm copying from a cell of a table with the command:
||
|| Selection.SelectCell
|| Selection.Copy
||
|| so that I can use this value later.
|| How can I "paste" or store what is in the clipboard into a
|| variable?

Is the selection straight text, or is there formatting and/or objects as
well?
Will the source document be closed before you need to recall the stored
selections?
What Word version?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org


Hi!
Yes, the selection is straight text.
No, the document I'm copying from is still open when I
need to recall the value: I need this value to be used in
the following 'ActiveDocument.SaveAs' command to save my
doc giving this value as name.
Microsoft Office Word 2003 (11.5604.5606)

Thanks
 
P

Peter Hewett

Hi <[email protected]>

This will do what you want:
Private Sub CopyPasteTest()
Dim doClipBoard As MSForms.DataObject
Dim strClipboardText As String

Set doClipBoard = New MSForms.DataObject

' Dummy test data - just copy whatever's selected in the doc
Selection.Copy

doClipBoard.GetFromClipboard

strClipboardText = doClipBoard.GetText(1)
MsgBox strClipboardText
End Sub

If you don't have a Form in your project you'll need to manually create a reference to
"Microsoft Forms 2.0 Object Library".

HTH + Cheers - Peter
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < (e-mail address removed) > écrivait :


|| Hi!
|| Yes, the selection is straight text.
|| No, the document I'm copying from is still open when I
|| need to recall the value: I need this value to be used in
|| the following 'ActiveDocument.SaveAs' command to save my
|| doc giving this value as name.
|| Microsoft Office Word 2003 (11.5604.5606)
||

Why go through the clipboard then?

Why not just declare a variable and use the cell to fill it?

Instead of using
Selection.SelectCell
Selection.Copy
try
'_______________________________________
Dim MyVar As String

With Selection.Cells(1).Range
MyVar = Left(.Text, Len(.Text) - 2)
End With
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top