PDA

View Full Version : How to copy shapes from one document to another



xsintill
11-10-2010, 08:29 AM
I am using word 2007 in combination with Delphi.

The destination document already has the same sections as the source document but missing it's shapes. What is the best way to copy the shapes from the source to do this. There is an extra condition which doesn't allow shapes above and under certain positions

fumei
11-10-2010, 11:48 AM
These are definitely Shapes, not InlineShapes?

xsintill
11-11-2010, 12:30 AM
i use Selection.Range.ShapeRange to iterate through it's shapes. If it has shapes. I select the shapes individually. Check if the properties meet the conditions and then select the shape and then do a selection.copy. after that i do a selection.paste in the destination.

I can copy them but they tend to get a different position/page when I paste them into the destination document, so i was thinking i have a wrong approach in solving this. So I was hoping someone knows how this should be done.

Thanks in advance

fumei
11-12-2010, 10:56 AM
"the conditions"

THE conditions? What conditions?

Since you did not bother to answer the question directly, I can only assume that when you say "if it has shapes" that you are indeed checking for Shapes, rather than InlineShapes.

If they are Shapes, then they have an Anchor, and getting the Anchor to match in the new document will be very difficult.

fumei
11-12-2010, 11:25 AM
It may help if you describe things fully. If you copy a chunk of a document, and that chunk includes Shapes, when you Paste into another document, the Shapes are there and in the correct position...

IF the destination document has the same margins, and there are no changes to Styles. In other words, IF the desitination document is set up the same, a copy that includes Shapes should copy correctly.

xsintill
11-12-2010, 11:00 PM
ok here is the description of the project i am working on.
the source document's text should be stripped of all it's styles when copied into the destination document. The destination document is using a provided template. Shapes in the upper part(below 40) and the lower part(above 525) of a page should not be copied. certain patterns should be replaced.

Copy the text without style into the destination is done. the next task would be to copy the shapes with the above condition into the destination. I have tried doing this iterating through sections and pages but without succes(position problems). In a test situation i succeeded yesterday iterating through characters with inlineshapes and shapes. But in the document going to be used there seems to be characters gone. I will do some investigation to see what was left out in the earlier conversion hopefully that way i can position the inlineshapes correctly. Otherwise maybe i should create some character patterns at the place of the inlineshapes before the actual text conversion so i can find the inlineshape places correctly.

I am not a vba programmer nor am i word 2007 user. a lot of the concepts are a bit new to me. The actual project is done in delphi. But the testing i want to do now in VBA since that seems to works a little faster. after i have a solution i can port it to delphi.

macropod
11-13-2010, 03:43 AM
Hi xsintill,

Your reference to:

Shapes in the upper part(below 40) and the lower part(above 525) of a page is at best ambiguous. Below 40 what? Above 525 what? And how does an 'upper part' translate into below 40, etc?

In any event, your process is circuitous and inefficient. It would be far simpler and more efficient to copy the desired range, paste it into the target document and then change the text formatting in the target document. That way you've got the text and the relevant shapes all correctly positioned in one go.

fumei
11-15-2010, 11:40 AM
Exactly.

In other words, copy everything (text and shapes), and then remove the styles. As I stated, if you copy the chunk, the Shapes are in the same places. Removing the styles is easy.