Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA-Excel: Get Text from the Windows Clipboard

In ear­lier ses­sion you saw how to put text in the win­dows clip­board(Putting Text In The Win­dows Clip­board) using PutIn­Clip­board() and Data Object. In this ses­sion you will learn how to get the text from the clipboard.

For Get­ting the text from the Clip­board, Fol­low the below steps.

Steps:

  •         Ini­tial­ize the Data Object, the type of MSForms.DataObject
  •         Get the text from the clip­board using Data Object
  •         Get the text out of Data Object using Get­Text() method.


Ini­tial­ize the Data Object, the type of MSForms.DataObject
Dim obj­Data As New MSForms.DataObject
Get the text from the clip­board using Data Object
objData.GetFromClipboard
Get the text out of Data Object using Get­Text() method.
objData.GetText()

Com­plete Code:

Function FnGetTextFromClipBoard()

    Dim objData As New MSForms.DataObject
    Dim strText

       objData.GetFromClipboard
       strText = objData.GetText()

       MsgBox strText

End Function 

Note:  For work­ing with Win­dows Clip­board you need DataOb­ject, the object in MSForms library. It pro­vides sup­port for text-string.
For that you must add the ref­er­ence “Microsoft Forms 2.0 Object Library”
How to add “Microsoft Forms 2.0 Object Library”

 

Read About:

Stor­ing mul­ti­ple data In the Win­dows Clipboard

Putting Text In The Win­dows Clipboard

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: