Clear Clipboard Contents

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Clear Clipboard Contents

Post by santosm »

Hi All,
Is there a way to clear the clipboard contents using VBA? I don't want to turn it off, I only want to clear what is currently located there.

Thanks,
Mark
Thanks,
Mark

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Clear Clipboard Contents

Post by HansV »

Select Tools | References...
Click Browse...
Type FM20.DLL in the Filename box.
Click OK.

You can now use code like this:

Code: Select all

Sub ClearClipboard()
    Dim objData As New MSForms.DataObject
    objData.SetText ""
    objData.PutInClipboard
    Set objData = Nothing
End Sub
Best wishes,
Hans

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Re: Clear Clipboard Contents

Post by santosm »

Hi Hans,
So cool! Do you have any handy code that will grab a screen capture of the active window? The code I mentioned earlier is not as reliable as I would like.

Thanks,
Mark
Thanks,
Mark

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Clear Clipboard Contents

Post by HansV »

I'm afraid not - the code that you posted is the "standard" way to perform a screen capture in VBA.
Best wishes,
Hans

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Re: Clear Clipboard Contents

Post by santosm »

Sometimes when I execute the code, I get a RTE 7, out of memory. I am not sure what this is really telling me.
Thanks,
Mark

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Re: Clear Clipboard Contents

Post by santosm »

Hi Hans,
Looking at this standard code, is there an option to save as JPEG instead of BMP???

Thanks,
Mark
Thanks,
Mark

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Re: Clear Clipboard Contents

Post by santosm »

HI Hans,
Looking at my code, I see why I can't grab the active msgbox window. I click OK before copying to the clipboard, hence the msgbox is closed. I will instead capture the form name, module, etc and store that in a table.

Mark
Thanks,
Mark

BenCasey
4StarLounger
Posts: 495
Joined: 13 Sep 2013, 07:56

Re: Clear Clipboard Contents

Post by BenCasey »

santosm wrote:Hi Hans,
Looking at this standard code, is there an option to save as JPEG instead of BMP???

Thanks,
Mark
You may care to look at this http://www.utteraccess.com/forum/lofive ... 48262.html
Regards, Ben

"Science is the belief in the ignorance of the experts."
- Richard Feynman

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Re: Clear Clipboard Contents

Post by santosm »

Thanks Ben,
That code is exactly what I am using and it seems to work OK sometimes, but I am still getting a lot of RTE 7 (out of memory) when the clipboard is first empty and it gets to the line where it wants to save the file. If I run in break mode, it always works.

Thanks,
Mark
Thanks,
Mark

BenCasey
4StarLounger
Posts: 495
Joined: 13 Sep 2013, 07:56

Re: Clear Clipboard Contents

Post by BenCasey »

santosm wrote:Thanks Ben,
That code is exactly what I am using and it seems to work OK sometimes, but I am still getting a lot of RTE 7 (out of memory) when the clipboard is first empty and it gets to the line where it wants to save the file. If I run in break mode, it always works.

Thanks,
Mark
You might try loading the clipboard with some stuff when you first start and then see if it still fails when invoked.
Regards, Ben

"Science is the belief in the ignorance of the experts."
- Richard Feynman