ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Check for blank clipboard (https://www.excelbanter.com/excel-discussion-misc-queries/220596-check-blank-clipboard.html)

Mr. Clean

Check for blank clipboard
 
In an Excel 2003 macro, how do I check for a blank (empty) clipboard?

Chip Pearson

Check for blank clipboard
 
If you want to test whether the user is in the process of a copy or
cut operation within Excel, you can use

Select Case Application.CutCopyMode
Case xlCopy
Debug.Print "Copy in progress"
Case xlCut
Debug.Print "Cut in progress"
Case Else
Debug.Print "No copy/cut in progress"
End Select


This returns that status of Excel's clipboard, returning true if there
is a copy or cut pending (the range has the marching ants border). You
can cancel the copy/cut mode with

Application.CutCopyMode = False


If you really need to see if *anything* (including non-Excel related
stuff) is in the clipboard, use


Public Declare Function CountClipboardFormats Lib "user32" () As Long

Sub AAA()
Dim N As Long
N = CountClipboardFormats()
If N = 0 Then
Debug.Print "nothing on clipboard"
Else
Debug.Print "something on clipboard"
End If
End Sub

If you want to totally clear the clipboard, use

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

Sub ClearClipboard()
OpenClipboard 0&
EmptyClipboard
CloseClipboard
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





On Thu, 12 Feb 2009 08:36:18 -0800, Mr. Clean
wrote:

In an Excel 2003 macro, how do I check for a blank (empty) clipboard?



All times are GMT +1. The time now is 02:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com