For storing multiple data in Clipboard, Follow the below steps.

 

Steps:

  • Initialize the Data Object, the type of MSForms.DataObject
  • Initialize a String and an Integer.
  • Set the String into Data Object using SetText() method and provide format identifier
  • Put the data in ClipBoard using PutInClipboard
  • Fetch the data from ClipBoard using GetFromClipboard("format identifier")

Source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Function FnStoreMultipleDataInClipBoard()
 
Dim objData As New MSForms.DataObject
Dim strText As String
Dim intData As Integer
 
	'---
	Set objData = New MSForms.DataObject
	
	'---
	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 

 

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

 

 

For using MSForms.DataObject in your code you need library Microsoft Forms 2.0 Object Library

 

You have to find Microsoft Forms 2.0 Object Library in the VBA menu Tools > References list in that case you need to browse the file FM20.DLL file from the %windir%/system32 for 32bit system and %windir%/SysWOW64

 

Once you add the FM20.DLL, you can see the Microsoft Forms 2.0 Object Library is added to the ref­er­ence list

Vlastnost BuiltIn = True je standardni doplnek MS Office, BuiltIn = False oznacuje uzivatelsky definovany objekt napr. CommandBar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Sub Custom_CommandBars_Delete()
'----------------------------------------------------------------------
'
'----------------------------------------------------------------------
Const lc_Title              As String = "myMacro"
'Dim lo_CommBar             As CommandBar <-- vyzaduje knihovnu
Dim lo_CommBar              As Variant, _
    lv_CustomCommandBars    As String, _
    lv_CommBar_Int          As Integer
 
    For Each lo_CommBar In CommandBars
            
        If lo_CommBar.BuiltIn = False Then      ' <-- Custom command bar !
        
            lv_CustomCommandBars = lv_CustomCommandBars & vbCrLf & lo_CommBar.Name
            lv_CommBar_Int = lv_CommBar_Int + 1
            Debug.Print lo_CommBar.Name, lo_CommBar.NameLocal
    
        End If
    Next
    
    If lv_CommBar_Int = 0 Then
        MsgBox "Nebyly nalezeny zadne custom commandbars", vbInformation + vbOKOnly, lc_Title
    
    ElseIf MsgBox("Vymazat all custom commandbars?" & vbCrLf & _
                  lv_CustomCommandBars, vbQuestion + vbYesNo, lc_Title) = vbYes Then
        For Each lo_CommBar In CommandBars
            If lo_CommBar.BuiltIn = False Then ' <-- Custom command bar !
                lo_CommBar.Delete
            End If
        Next
    End If
    
End Sub