View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Test if Clipboard is empty

Tod,

You can use the CutCopyMode property to determine whether Excel
is in Copy mode (CutCopyMode = 1 = xlCopy), Cut mode (CutCopyMode
= 2 = xlCut) or neither (CutCopyMode = 0)

When you copy data to the clipboard in Excel, a few dozen data
formats are place in the clipboard. To determine whether an Excel
data type (e.g., BIFF8) is in the clipboard, you need to
enumerate all the data formats on the clipboard, testing each
one. For example,


Public Declare Function EnumClipboardFormats Lib "user32" _
(ByVal wFormat As Long) As Long
Public Declare Function OpenClipboard Lib "user32" _
(ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function GetClipboardFormatName Lib "user32" _
Alias "GetClipboardFormatNameA" _
(ByVal wFormat As Long, ByVal lpString As String, _
ByVal nMaxCount As Long) As Long

Public Declare Function CountClipboardFormats Lib "user32" () As
Long
Public Declare Function IsClipboardFormatAvailable Lib "user32" _
(ByVal wFormat As Long) As Long
Public Declare Function GetClipboardData Lib "user32" _
Alias "GetClipboardDataA" (ByVal wFormat As Long) As Long

Const cBIFF8Format = 49755


Sub AAA()

Dim R As Long
Dim S As String
Dim O As Object

Selection.Copy
OpenClipboard 0
Do
R = EnumClipboardFormats(R)
S = String(255, 0)
GetClipboardFormatName R, S, Len(S)
Debug.Print R, S
Loop Until R = 0
Debug.Print "Format Count:", CountClipboardFormats
Debug.Print "Excel Data Available:",
IsClipboardFormatAvailable(cBIFF8Format)

CloseClipboard

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Tod" wrote in message
...
Here is my newbie question o' the day.

Is there a way I can test if something has been copied to
the clipboard?

Extra super monster bonus question:

Is there a way to also test if the data that has been
copied to the clipboard is cell values (vs an object or
some non-excel data)?

tod