Excel請問VBA怎樣實現清空剪貼板?
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 過程,之后便會看到剪貼板被清空了。