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”
Now, For putting text in the Clipboard, Follow the below steps.
• Initialize the Data Object, the type of MSForms.DataObject
• Create a String
• Set the String into Data Object using SetText() method.
• Put the data in ClipBoard using PutInClipboard
Initialize the Data Object, the type of MSForms.DataObject
Dim objData As New MSForms.DataObject
Create a String
strText = “I will be in ClipBoard”
Set the String into Data Object using SetText() method.
Put the data in ClipBoard using PutInClipboard
Function FnPutDataInClipBoard() Dim objData As New MSForms.DataObject Dim strText strText = "I will be in ClipBoard" objData.SetText strText objData.PutInClipboard End Function
NOTE: Now if you open the Notepad and press Ctrl+V, you can see that string you had put in, gets pasted in the Notepad