Consulting

Results 1 to 5 of 5

Thread: Solved: How to clear the images on the clipboard?

  1. #1

    Solved: How to clear the images on the clipboard?

    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

    [VBA] Sub clipboard()

    Dim MyData As DataObject

    Set MyData = New DataObject
    MyData.SetText ""
    MyData.PutInClipboard
    End Sub[/VBA]

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Hi

    The method I use is in this kb article.
    K :-)

  3. #3
    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

  4. #4
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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 this[VBA]Option 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[/VBA]
    (I'll probably get into trouble with someone for encouraging debugging with message boxes - apologies to purists in advance )

    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.

    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
    K :-)

  5. #5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •