Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to empty the clipboard? 1

Status
Not open for further replies.

JensKKK

Technical User
May 8, 2007
119
GB
My application is using the clipboard to transport grpahics from one application to another. Ideally I want to reduce the memory usage by deleting pictures from the clipboard after the job is done, but so far are my apporaches not very succesful.

I have tried two things so far, but when looking at the office clipboard in Excel (in the Edit menu). The clipboard remains full.

Here is what I have done so far

1) recorded a macro and deleted clipboard manually

Sub Macro1()
'
' Macro1 Macro

'
Application.CutCopyMode = False
End Sub


This does not work.

The other idea was to copy an empty string and paste it into the clipboard.

Sub ClearClipboard()
Dim DatObj As DataObject
Dim error_string As String
On Error GoTo errorhandler
Set DatObj = New DataObject
DatObj.SetText ""
DatObj.PutInClipboard

Exit Sub
errorhandler:
error_string = err.number & " " & err.Description
Application.Run "P_ErrorHandler", 4, error_string
End Sub

That does not empty the clipboard.

Any suggestions how to empty the clipboard more efficiently.
 
Or maybe another thread from this forum thread705-1394933

Everybody is somebodys Nutter.
 
Thanks for that Chris,

but it seems that I can add now a third method to my list of routines that are nor working.

Unless I have installed it wrongly. (I followed the instructions from the webpage above).

My control is that I have the Clipboard window open and the clearly contains pastable items after the execution of the clearclipboard macro.

 
Here is a routine that seems to empty the clipboard.

To get the routine to work the two cells that get copied must not contain anything.

The office clipboard contains 24 spaces and therefore runs the routine 24 times. To empty all clipboard spaces with "".

Hope that is usful to anybody else.


Sub ccc()
Dim i As Integer
For i = 1 To 2
Sheets("input bsl").Select
Sheets("input bsl").Cells(i, 250).Select
Selection.Copy
Next
End Sub
Sub clearclipboard()
'
' Macro3 Macro
' Macro recorded 17/09/2007 by jkoopmann
'
For i = 1 To 12
Application.Run "ccc"
Next
End Sub
 
The API version (first linked to the VBAX KB entry) will work on versions 97-2007, whereas the second one (with DataObjects) will not work in all versions. Like other functional areas of VBA, it was cut out of the 2007 Object Model (much to my disliking).

I'm not sure if you're using 2007 or not, but in any case, try the API method.

HTH

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Firefytr,

I used the API method, but it did not empty the clipboard.

Just to explain you how I come to this conclusion. I opened the Clipboard window from the Edit menu and looked at the 24 items that are on display. By running the API method all picture that copied previously into the cliboard remained there.

Do you think that is a installation problem? I am running Excel 2002.

Any comment is appreciated.
 
Ah, well, there is a difference between the Windows Clipboard and the Office Clipboard. Welcome to clipboard hell. ;)

If you are using Office 2000 you can clear the Office clipboard via VBA...

Code:
CommandBars("Clipboard").Controls("Clear Clipboard").Execute

If you are not using 2000, you cannot clear it at all. It became a Task Pane in XP (2002) and beyond with relatively no programmatic access to it. There may be a way by using VB.NET to create an add-in which customizes the task panes, but I'm certainly not sure if that is even possible; if it is, I'd think that would be the only way.

Sorry, this is one place where Microsoft really took a nose dive and screwed up (imho).

HTH

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top