Set variable to clipboard contents?

  • Thread starter Thread starter Fred Smith
  • Start date Start date
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?
 
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.
 
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
 

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

Back
Top