Clipboard.GetText

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In VB6 I can get the (text) contents of the system clipboard within my app

Debug.Print Clipboard.GetText

I can't seem to do this in VBA. Is there a way to get the clipboard text
into my procedures?

Thanks
 
Charlie,

Set a reference to the MSForms 2.0 library, and use code like the
following:


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


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Charlie said:
In VB6 I can get the (text) contents of the system clipboard within my app
Debug.Print Clipboard.GetText
I can't seem to do this in VBA. Is there a way to get the clipboard text
into my procedures?

Hi Charlie,

It's a bit more convoluted and not as flexible, but you can do it in VBA
by setting a reference to the Microsoft Forms 2.0 Object Library (which is
set automatically if you add a UserForm to your project) and doing something
like this:

Dim objDataObject As MSForms.DataObject
Set objDataObject = New MSForms.DataObject
objDataObject.GetFromClipboard
Debug.Print objDataObject.GetText

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm
 
Thanks to both of you!

Rob Bovey said:
Hi Charlie,

It's a bit more convoluted and not as flexible, but you can do it in VBA
by setting a reference to the Microsoft Forms 2.0 Object Library (which is
set automatically if you add a UserForm to your project) and doing something
like this:

Dim objDataObject As MSForms.DataObject
Set objDataObject = New MSForms.DataObject
objDataObject.GetFromClipboard
Debug.Print objDataObject.GetText

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm
 

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