Clipboard: pasting last two (or all) items from Word clipboard and clearing clipboard.

P

Philip

I copy two pices of text from another program and need some VBA way of
1 pasting them into Word in the order copied, then clearing the
Clipboard,
2 adding various other stuff below the pastes (have macro for this),
3 manually entering three bits of text in separate positions in the table
formed by (2),
4 format the text, and print the page (have another macro for this).

What I'd like to do is combine the lot into one macro. I think I know how to
do (3) [but suggestions welcome!], but how do I do (1)??? It is not
something I can macro record.
The pastes contain different info but are always the same number of lines
and the manually typed stuff varies but is always in the same places.

Philip
 
P

Peter Hewett

Hi Philip

I'm afraid you're out of luck. Although you can copy ann paste multiple pieces of data
within Office applications you can't do it either from another application or
programmatically from within Office. There are in fact two clipboards the general one
shared by all applications which holds just one piece of data and a clipboard private to
the Office applications which can hold multiple items of data. Unfortunately Microsoft
did not bother to expose an API for the Office clipboard so you can't use it from VBA
etc..

You will need to restructure your requirements to do two cut/copy and pastes.

You can find help on working with the clipboard here:

Manipulating the clipboard using VBA
http://word.mvps.org/faqs/macrosvba/ManipulateClipboard.htm

Of you still need help after reading this article post again.

HTH + Cheers - Peter
 
J

Jay Freedman

Hi Philip,

You have a bit of a Catch-22 situation here.

- If you're using the Windows clipboard, it can hold only one item at
a time. Then you have the problem of locating the second item in the
other program before the macro can copy/paste it.

- If you're using the Office clipboard, which is a whole separate
mechanism from the Windows clipboard, you can't do anything with it in
VBA because Microsoft has never provided any automation interface for
it. According to http://support.microsoft.com/?kbid=221190, "There is
no Visual Basic for Applications object model for the Office
Clipboard, so there is no way to programmatically manipulate it."

However, if the other program is an Office program (Excel, Access,
PowerPoint, etc.) then you don't need a clipboard to move data from it
to Word. For example, see
http://word.mvps.org/FAQs/InterDev/ControlXLFromWord.htm.
 

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

Top