VBA code for cleaning the clipboard

  • Thread starter Thread starter Thrava
  • Start date Start date
T

Thrava

Hi group.

I'm copying charts and pasting them in a sheet all in VBA.

What is the code for me to clear everything in the
clipboard after the charts are pasted?

Thanks
Thrava
 
Hi
have a look at
http://tinyurl.com/3yoqc


Try for example the following code:

Public Declare Function OpenClipboard Lib "user32" ( _
ByVal hwnd AsLong) 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
 
Hi Thrava!

Here's an extract from a Chip Pearson post:

Extract >>

You can completely empty the Windows clipboard with code like

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

<< End Extract.

Chip also covers the issue at:

http://www.cpearson.com/excel/clipboar.htm

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
Hi Thrava!

Note that Frank and I both came up with the same solution.

I'd bet a Single Malt that Frank used Google Search 6.0 from Ron de
Bruin to find that reference.

Google search 6.0 is available free from:

Ron de Bruin
http://www.rondebruin.nl/Google.htm

You can download a User Guide as well but it has a very intuitive user
interface. It places a new item under menu that allows very easy
searching for answers to common and not so common problems. Help where
you want it when you want it!

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
thank you Norman

-----Original Message-----
Hi Thrava!

Here's an extract from a Chip Pearson post:

Extract >>

You can completely empty the Windows clipboard with code like

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

<< End Extract.

Chip also covers the issue at:

http://www.cpearson.com/excel/clipboar.htm

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.



.
 
thank you Frank

-----Original Message-----
Hi
have a look at
http://tinyurl.com/3yoqc


Try for example the following code:

Public Declare Function OpenClipboard Lib "user32" ( _
ByVal hwnd AsLong) 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

--
Regards
Frank Kabel
Frankfurt, Germany

.
 
Norman said:
Hi Thrava!

Note that Frank and I both came up with the same solution.

I'd bet a Single Malt that Frank used Google Search 6.0 from Ron de
Bruin to find that reference.

Won :-)
Though in this case it was just a repost from some days ago (but for
that post I used Ron's fantastic add-in)
 
Hi,
I've tried this but I'm getting an error message
Its a compile error saying:

constants, fixed length strings, arrays, user-defined
types and declare statemtents not allowed as public
members of Object module.


What does it mean?
 
Hi
try the following:
- create a new standard module
- paste the complete code in this new module
- try again
 
Hi Thrava!

Where did you put the code.

The declarations need to be at the top of the module. I'd prefer this
type of sub to be in a Module on it's own.

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
Hi Guys,
Sorry for delayed response, hope you're still checking.
I got stuck in traffic

Anyway, I need to keep this within Sheet1 because its part
of my command button even driven sub
Now what do I do?
 
Hi
you have to put it in a standard module :-)
you can call this macro then from your command button routine
 
Thrava,

Change the declaration to Private. E.g.,

Private Declare Function CloseClipboard Lib "user32" ()


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top