Copy the contents of the clipboard to a specific cell of the first table

A

andreas

Dear Experts:

I would like to achieve the following using VBA:

1. Copy the FIRST graphic (could be inline with text or floating over
text or else) of the current document to the clipboard.
If this first graphic is not 'inline with text', the graphic is to be
converted into an 'inline with text' shape before being copied to the
clipboard.

2. Insert the contents of the clipboard into cell (row: 3, column: 2)
of the FIRST table of the current document.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
 
T

Tony Jollans

Define First Graphic!

You could have several floating graphics on a page, perhaps some inside Page Headers, or Text Boxes, and checking them all for absolute top and left, say, and comparing that with the position of inline graphics, allowing for the fact that graphics may be superimposed on one another, and given that 'Page' is a fairly fluid concept in Word, is non-trivial. What is the purpose of this?

Graphics on the Clipboard are just graphics; they neither float over, nor exist inline with, anything.
 
A

andreas

Define First Graphic!

You could have several floating graphics on a page, perhaps some inside Page Headers, or Text Boxes, and checking them all for absolute top and left, say, and comparing that with the position of inline graphics, allowing for the fact that graphics may be superimposed on one another, and given that'Page' is a fairly fluid concept in Word, is non-trivial. What is the purpose of this?

Graphics on the Clipboard are just graphics; they neither float over, norexist inline with, anything.

--
Enjoy,
Tony

 www.WordArticles.com

Hi Tony,

I really appreciate your in-depth knowledge regarding this matter.
Thank you very much for that. In order not to complicate things, how
about this:

I just would like to be able to select the first graphic of the body
text using VBA. (First graphic could be Inline with text, or some
other 'word wrap'. In the documents in question there are no graphics
in headers, footers drawing canvasses or text boxes).

Is this possible?

Regards, Andreas
 
A

andreas

Hi Tony,

I really appreciate your in-depth knowledge regarding this matter.
Thank you very much for that. In order not to complicate things, how
about this:

I just would like to be able to select the first graphic of the body
text using VBA. (First graphic could be Inline with text, or some
other 'word wrap'. In the documents in question there are no graphics
in headers, footers drawing canvasses or text boxes).

Is this possible?

Regards, Andreas

Dear Tony,

I found out myself. Thank you anyway for your ever great help.

Sub SelectFirstGraphic()
Dim sh As Shape
Dim ilsh As InlineShape
Dim rng As Range

Dim docA As Document


Set docA = ActiveDocument
Set rng = ActiveDocument.Sections(1).Range

For Each sh In rng.ShapeRange
Select Case sh.Type
Case msoPicture, msoDiagram
sh.ConvertToInlineShape
End Select
Next sh

Set ilsh = docA.InlineShapes(1)
ilsh.Range.Select
End Sub
 
T

Tony Jollans

If you're happy, I'm happy!

However, that code does have the side effect of converting floating shapes to Inline before selecting the first Inline shape. Perhaps you should have an Undo loop at the end to reverse the changes.
 
T

Tony Jollans

Also, converting Shapes to Inline, moves them to (inline in) the paragraph they are anchored to, which is not necessarily where they were on the page.
 
D

dedawson

Beware of unintended consequences.

Consider a document with 5 floating and 5 inline shapes.

If you run a loop to convert all floating shapes to inline, you will
then end up with 10 inline shapes.

An Undo loop that converted all inline to floating would leave you
with 10 floating and 0 inline if you did not take care to somehow
identify which shapes were initially converted.

Simply relying on indexes is dangerous as they change as objects are
add/deleted from a collection.
 
T

Tony Jollans

An undo loop would only undo what was done. Of course you would have to know, or deduce, how far back to undo, but you could never undo what was not done in the first place.
 
D

dedawson

Was just warning of the danger in choice of approach to 'Undo'ing.
One could use Application.Undo, or one might have been tempted to loop
on the Inline Shapes collection.

With the first, one would want to be certain that no other actions had
been taken following completion of original conversion loop. With the
second, one would need to take care not to perform unwanted
conversions.
 
T

Tony Jollans

It's largely academic as the code won't really do what the OP asked, which, anyway, seems like an artificial exercise.
 
A

andreas

It's largely academic as the code won't really do what the OP asked, which, anyway, seems like an artificial exercise.

--
Enjoy,
Tony

 www.WordArticles.com

Hi Tony and dedawson,

thank you very much for your professional answers. I really appreciate
your concerns and are aware of the pitfalls of my code. But, as a
matter of fact, it is used in such a specific situation that it suits
perfectly my needs. It may look like an artificial exercise, but it is
of practical use for me.

Thank you. Regards, Andreas
 

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