Create a Timer control (or have it in a loop with DoEvents()
) and use GetClipboardData()
like so:
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Long, ByVal ByteLen As Long)
Private Sub Timer1_Timer()
Dim ptr As Long
OpenClipboard hwnd
ptr = GetClipboardData(49158)
If ptr Then
Dim size As Long
size = lstrlen(ptr)
If size > 0 Then
Dim data As String
data = Space$(size)
CopyMemory ByVal data, ByVal ptr, size
MsgBox data
End If
End If
CloseClipboard
End Sub
FYI: 49158 is a private clipboard format called "FileName" and unfortunately cannot be used with Clipboard.GetData()
as the number is too high for an Integer.
When you copy something, the data
variable will contain the file name copied.