How to check if clipboard is empty of text?

后端 未结 1 403
盖世英雄少女心
盖世英雄少女心 2020-12-10 07:53

If I try to paste from an empty clipboard, I get an error. I would like to check if the clipboard is empty of text before pasting so that I can avoid this. How can this be

相关标签:
1条回答
  • 2020-12-10 08:43

    Very important: You must first set a reference to the "Microsoft Forms 2.0 Object Library" (as in the attached screenshot below) before implementing this code. You may find that it is not an option when you scroll through the reference libraries. To make it show up, just add a form to the project (you can always delete the form later).

    Sub CheckClipboard()
    
            Dim myDataObject As DataObject
    
            Set myDataObject = New DataObject
    
    
            myDataObject.GetFromClipboard
    
    
            If myDataObject.GetFormat(1) = True Then 
    
                '''There is text on clipboard, so it's safe to paste
    
            Else 
                '''there is no text on the clipboard, so you may get error.
    
            End If
    
    End Sub
    
    0 讨论(0)
提交回复
热议问题