VBA 参考代码:
Option Explicit
#If VBA7 Then
Public Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hwnd As LongPtr) As Long
Public Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
Public Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long
#Else
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As LongPtr) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
#End If
Sub CallEC()
Dim lngRet As Long
lngRet = OpenClipboard(Application.hwnd)
If lngRet Then
EmptyClipboard
CloseClipboard
End If
End Sub
先复制一段文字到剪贴板,然后运行 CallEC 过程,之后便会看到剪贴板被清空了。