ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Set variable to clipboard contents? (https://www.excelbanter.com/excel-programming/309065-set-variable-clipboard-contents.html)

Fred Smith

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

--
Thanks,
Fred




Bob Kilmer

Set variable to clipboard contents?
 
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 Smith" wrote in message
...
Is it possible to set a variable to the contents of the clipboard? That

is,
what is the VBA equivalent of MyVar = Ctrl-V?

--
Thanks,
Fred






Chip Pearson

Set variable to clipboard contents?
 
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



"Fred Smith" wrote in message
...
Is it possible to set a variable to the contents of the
clipboard? That is,
what is the VBA equivalent of MyVar = Ctrl-V?

--
Thanks,
Fred







All times are GMT +1. The time now is 07:23 PM.

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