View Single Post
  #18   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
Tony Jollans Tony Jollans is offline
external usenet poster
 
Posts: 13
Default Clear Office Clipboard from VBA?

I've tried clearing this Office clipboard using the code that Jonathat
gave
me, but the problem persists.


As I tried to explain in one of my posts, I wouldn't expect it to make any
difference.

If I step through my code, it always works perfectly. So debugging is
next
to impossible.


In this case it is probably a timing (or perhaps a locking) problem. It is
worth trying to put one or more DoEvents statements in the code to allow the
system to catch up with itself. Precise logic behind this is often
impossible to explain but trial and error can sometimes lead to a
resolution.

Chris Pearson's web site (at least I *think* that is his name)


It's Chip Pearson but I don't think he'll mind :-)

You said originally that the problem was with images yet you are copying a
paragraph range - does it contain images? And, if so, are they linked?

--
Enjoy,

Tony Jollans
Microsoft Word MVP

"theLuggage" wrote in message
...
Hi Tony,

I've tried clearing this Office clipboard using the code that Jonathat
gave
me, but the problem persists.

If I step through my code, it always works perfectly. So debugging is
next
to impossible.

Anyway, here's the answers to your questions:

"can you verify that your copies have worked?" I have verified it as best
I
can. As I said, when I step through my code it always works perfectly.
To
copy the image I use this code:
Selection.Paragraphs(1).Range.Copy

I've also tried it with:
Selection.Paragraphs(1).Range.Selection
Selection.Copy

Using the select first, then copy approach, I can see that the correct
image
is always being selected.


Next questions: "Can you verify that your clearing of the Windows
clipboard
has worked?" Yes, using the C:\winnt\system32\clipbrd.exe application that
one of the posters mentioned, I can see that the clipboard does get
cleared.

And your last question: "What do you do between copying and pasting?" I
don't do anything other than switch to Excel, move to a particular range,
and
then paste. Here's the exact code:
' Up to this point, I am moving the cursor one paragraph at a time
down the
' document until I find an image. When I've got to one I do this
ClearClipboard ' This is the Windows API call code that I found on
Chris Pearson's web site (at least I *think* that is his name)
CommandBars.FindControl(ID:=3634).Execute

' Get the figure itself
Selection.Paragraphs(1).Range.Copy

mobjExcelApp.ActiveCell.Offset(1, 0).Activate
mobjCurrentSheet.Paste

ClearClipboard


The code is running within MS Word, so mobjExcelApp and mobjCurrentSheet
are
references to the Excel application and the current worksheet.

Thanks for the help with this (extremely bizarre) problem!

"Tony Jollans" wrote:

I just went back and re-read the original post and the problem really
should
have nothing to do with the Office Clipboard.

Loosely, what happens is this: when you do a Copy operation the Windows
Clipboard is cleared and whatever it is you are copying is placed in the
Windows Clipboard. It may be added in several different formats (it's not
really relavant now, but some of them may go onto the clipboard itself,
some
of them may be pointers for the originating application to act on later
request). When you do a Paste, the Windows Clipboard is asked to provide
whatever is on it in the format you want and, providing that format is
available, it will provide it, but still maintain whatever it holds for
you
to do further Pastes if you wish. In normal circumstances you should not
need to do an explicit emptying of the clipboard yourself.

Separate to all this there is, again (very) loosely, a Windows event
fired
when something is added to the Windows Clipboard which allows Office to
know
that it has happened and take a copy for the Office Clipboard. Entirely
separate from the Windows Clipboard, the Office Clipboard maintains its
own
copies of up to 12 (Office 2000) or 24 (later versions) items. Office
provides some UI facilities for manipulating the copies it holds but they
are not directly available from code and no Paste operation, other than
explicitly from the Office Clipboard, will use them. If you do do an
explicit Paste from the Office Clipboard (via the UI) what actually
happens
is that a (Windows) Copy operation is triggered to copy from the Office
Clipboard to the Windows Clipboard and a (Windows) Paste operation is
then
triggered to paste from the Windows Clipboard to the specified
destination.

I confess myself at a total loss to explain how something that has been
removed from the Windows Clipboard can later be Pasted; it can only
happen
if it has be re-placed (i.e. re-copied) on to the Windows Clipboard
again -
whether explicitly or implicitly as part of some other operation. So the
immediate questions must be: can you verify that your copies have worked?
can you verify that your clearing of the Windows clipboard has worked?
and
what do you do between copying and pasting?

--
Enjoy,

Tony Jollans
Microsoft Word MVP

"Tony Jollans" <My forename at my surname dot com wrote in message
...
If you are using Office 2000 you do have some indirect access to the
Office Clipboard from VBA - but you do not have it in any later
versions.

In Office 2000 the Office Clipboard is presented as a CommandBar and so
you can programmatically manipulate the Controls, for example ...

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

In Office XP and later, the Office Clipboard is presented as a Task
Pane
and the 'back door' has been shut. AFAIK, VBA access to it post-2000 is
impossible - I don't think you can even do it with SendKeys (but don't
quote me on that).

--
Enjoy,

Tony Jollans
Microsoft Word MVP

"theLuggage" wrote in message
...

I meant to say this in my original post: we're using Office 2000 for
Windows. There is no Edit--OfficeClipboard in Office 2k that I can
see.

In any case, I need to do this in VBA code, not via a UI.

"JLGWhiz" wrote:

You can access the Office Clipboard EditOfficeClipboard in Excel.
It
should
show what is on it, if anything, from whatever source. You can then
edit it
one item at a time or all at once. See Excel help on Clipboard.

"theLuggage" wrote:

I found some code on the web to manipulate the Windows clipboard
using
windows API calls.

Is there a way to manipulate the MS Office clipboard?

Here's the scenario. I've got some code that parses through a Word
document
and copies all the tables and images from the Word document into an
Excel
Workbook. The tables all work fine, but the images are sometimes
duplicated.
Instead of getting image 1 and then image 2, I get two copies of
image 1.

Even though I clear the clipboard (using the Windows API calls)
before
I
copy the figure, sometimes I still get the duplicate.

I ran my code with the Office clipboard command bar showing and it
looks
like the Office clipboard doesn't get cleared at all. To show the
Office
clipboard, I'm just choosing View--Toolbars--Clipboard.

Is there a way to clear the Office clipboard?

Thanks in advance for the help!

(Forgive the cross-post. I'm not sure where to post the question.)