Home > Software engineering >  How to judge whether a clipboard is empty
How to judge whether a clipboard is empty

Time:10-11

Do you have no one know how to judge the clipboard is empty
If you use the following code, tip: when clipboard is empty dataobject: gettext invalid formatetc structure, do you have no one is there any other way to

Due to the DataObject is a member of the Form object, so you have to add a Form, empty Form to also go
1. The Option Explicit
2. 'to determine whether a clipboard is empty
3. The Function CheckClipboard () As a Boolean
4. Dim MyData As DataObject, MyStr As String
5. Set MyData DataObject=https://bbs.csdn.net/topics/New
6. MyData. GetFromClipboard 'get clipboard content
7.
8. MyStr=MyData. GetText 'assigned to the variable
9.
10. If MyStr="" Then
11. CheckClipboard=False
12. The Else
13. CheckClipboard=True
14. End If
15. End Function
16.
17. Sub test ()
18. MsgBox CheckClipboard
19. The End Sub
The above code to provide a net friend

CodePudding user response:

 Option Explicit 

'whether the clipboard is empty
As a Boolean Function CheckClipboard ()
If the Clipboard. The GetText="" Then
CheckClipboard=False
The Else
CheckClipboard=True
End the If
End the Function

Private Sub Command1_Click ()
MsgBox CheckClipboard
End Sub

Private Sub Command2_Click ()
The Clipboard. The Clear
End Sub
  •  Tags:  
  • VBA
  • Related