PDA

View Full Version : Solved: How to clear the images on the clipboard?



vicenflor
10-31-2005, 02:50 PM
Hello,

Could anybody help me with code to clear all images and contents on the clipboard? The reason is that I want to get rid of the message "You placed a large amount..." when I stop my application. The code below, which I have found on the internet, seems not to work for me although I have a userform in my application which is required. Also the forms 2.0 object library is selected.

Thanks for any help

Vicenflor

Sub clipboard()

Dim MyData As DataObject

Set MyData = New DataObject
MyData.SetText ""
MyData.PutInClipboard
End Sub

Killian
10-31-2005, 03:05 PM
Hi :hi:

The method I use is in this (http://vbaexpress.com/kb/getarticle.php?kb_id=205) kb article.

vicenflor
11-01-2005, 12:35 PM
Hi Killian,

I tried your code following the instructions you made, but nothing seems to happen with my clipboard??? I did the test by placing some pictures on the clipboard and then running your macro, but all the pictures are still there. Is there something I do wrong? Even if I use the ccc.xls file, nothing happens.

Vicenflor

Vicenflor

Killian
11-02-2005, 05:42 AM
Well I think there may be some confusion here...
firfytr's KB entry deals with clearing the Windows clipboard - there's no reason why running the code in the attachment (ccc.xls) won't work.
Each of the Win API functions (OpenClipboard, EmptyClipboard and CloseClipboard) returns a Long, 0 for failure and non-zero otherwise so you could test if they are working like thisOption Explicit

Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function CloseClipboard Lib "user32" () As Long

Public Function ClearClipboard() As Boolean
'if any of these function calls fails,
'they'll return 0 in the messagebox
MsgBox "OpenClipboard - " & OpenClipboard(0&)
MsgBox "EmptyClipboard - " & EmptyClipboard
MsgBox "CloseClipboard - " & CloseClipboard
End Function

Sub test()
ClearClipboard
End Sub
(I'll probably get into trouble with someone for encouraging debugging with message boxes - apologies to purists in advance :blush)

However, the "Office Clipboard" is a different matter - If you are looking at the objects in the Office Clipboard Task Pane and clear the Windows Clipboard, they're still there - that's because they are two different things.
TonyJollans has written an excellent article on this subject that you can view here (http://www.vbaexpress.com/forum/articles.php?action=viewarticle&artid=50).

There isn't (AFAIK) a direct command for clearing the Office Clipboard - one way is to use execute the command bar button for it (Application.CommandBars(...).Controls(...).Execute) but it 's in a different position from one Office version to the next and searching by name only works if you know which language Office is installed in :doh:

vicenflor
11-02-2005, 02:43 PM
Hello Killian,

By using the code you proposed, it seems that I do not get the message "you placed a large amount....." anymore when I quit my application. That was all I wanted to achieve. I assume that the pictures will be still available on the office clipboard, but that is not so important for me.

Thanks for the help.
Vicenflor