Be the first user to complete this post
|
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 working with Windows Clipboard you need DataObject, the object in MSForms library. It provides support for text-string.
For that you must add the reference “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