Be the first user to complete this post

  • 0
Add to List

VBA-Excel: Get Text from the Windows Clipboard

In earlier session you saw how to put text in the windows clipboard(Putting Text In The Windows Clipboard) using PutInClipboard() and Data Object. In this session you will learn how to get the text from the clipboard.

For Getting the text from the Clipboard, Follow the below steps.

Steps:

  •         Initialize the Data Object, the type of MSForms.DataObject
  •         Get the text from the clipboard using Data Object
  •         Get the text out of Data Object using GetText() method.


Initialize the Data Object, the type of MSForms.DataObject
Dim objData As New MSForms.DataObject
Get the text from the clipboard using Data Object
objData.GetFromClipboard
Get the text out of Data Object using GetText() method.
objData.GetText()

Complete 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:

Storing multiple data In the Windows Clipboard

Putting Text In The Windows Clipboard