Set variable to clipboard contents?

F

Fred Smith

Is it possible to set a variable to the contents of the clipboard? That is,
what is the VBA equivalent of MyVar = Ctrl-V?
 
B

Bob Kilmer

look up GetFromClipboard Method. Copies data from the Clipboard to a
DataObject. Your variable has to be a DataObject. You ca transfer from that
to other variable types.
 
C

Chip Pearson

Fred.

First, set a reference to the MSForms library (in VBA, Tools
menu, then References), and use code like the following:

Dim DataObj As New MSForms.DataObject
Dim S As String
DataObj.GetFromClipboard
S = DataObj.GetText
Debug.Print S

See also www.cpearson.com/excel/clipboar.htm .

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Top