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

VBA-Excel: Storing multiple data In the Windows Clipboard

In ear­lier ses­sions  you saw how to put text in the win­dows clip­board (Putting Text In The Win­dows Clip­board) with the help of PutIn­Clip­board() and Data Object and how to get the text from the Clip­board using Get­From­Clip­board() and Data Object.

In this ses­sion you will learn how to store mul­ti­ple data’s in Clip­board and retrieve them. For stor­ing mul­ti­ple data’s, you need to store val­ues as pair, Keys and Val­ues or you can say for­mat iden­ti­fier and while retriev­ing the data from the Clip­board you will use these for­mat iden­ti­fiers to get the data. This data can be String, Long, Integer.

For stor­ing mul­ti­ple data in Clip­board, Fol­low the below steps.

Steps:

•    Ini­tial­ize the Data Object, the type of MSForms.DataObject
•    Ini­tial­ize a String and an Inte­ger.
•    Set the String into Data Object using Set­Text() method and pro­vide for­mat iden­ti­fier
•    Put the data in Clip­Board using PutIn­Clip­board
•    Fetch the data from Clip­Board using GetFromClipboard(“format iden­ti­fier”)

Ini­tial­ize the Data Object, the type of MSForms.DataObject
Dim obj­Data As New MSForms.DataObject
Ini­tial­ize a String and an Inte­ger.
str­Text = “I am the First One“
int­Data = 5
Set the String into Data Object using Set­Text() method and pro­vide for­mat iden­ti­fier
objData.SetText str­Text, “StringOne”

Put the data in Clip­Board using PutIn­Clip­board
objData.PutInClipboard

Fetch the data from Clip­Board using GetFromClipboard(“format iden­ti­fier”)
objData.GetText(“StringOne”)

Com­plete Code:

Function FnStoreMultipleDataInClipBoard()

   Dim objData As New MSForms.DataObject

   Dim strText

   Dim intData

   strText = "I am the First One"

   intData = 5

   objData.SetText strText, "StringOne"

   objData.PutInClipboard

   objData.SetText intData, "IntegerOne"

   objData.PutInClipboard

   MsgBox "Data in ClipBoard : '" & objData.GetText("StringOne") & "' And '" &   objData.GetText("IntegerOne") & "'"

End Function 

  12.00

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”

ClipBoard-Store Multiple Data

ClipBoard-Store Mul­ti­ple Data

 

You may also like...

1 Response

  1. Teresita says:

    I do believe all of the ideas you’ve pre­seented to your post.

    They’re really con­vinc­ing and can def­i­nitely work. Still, tthe posts are too short for begin­ners.
    May just you please extend them a bit from sub­se­quent time?
    Thank you for the post.

Leave a Reply

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

%d bloggers like this: