Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Exporting Shapes/InlShps, replacing with Tags 1

Status
Not open for further replies.

MakeItSo

Programmer
Oct 21, 2003
3,316
DE
Hello friends,

I am trying to export all Shapes and InlineShapes in a document into a second document, delete them in the first and replace them there with identifiable Tags.
So where e.g. a text frame used to be in the original doc, I would only have this left:
[ignore]<text frame 1>
whereas the second doc would contain this:
<text frame 1>contents of the text field</text frame 1>[/ignore]

The export functions well, all shapes and inline shapes get exported, and the tags, too, are created fine.

Problem: they are not created where the shape used to be!
Instead, I end up with a sequence of tags of my former shapes on top of the document.
[sadeyes]

Neither the .select nor .activate helped me.
My last attempt was adding a bookmark before deletion, but alas: the bookmark, too, is created at the start of the document...
[ponder]

Here's the crucial part of the code:
Code:
For Each shp In original.Shapes
    shp.Select
    If shp.TextFrame.HasText Then
        shp.TextFrame.TextRange.Copy
    Else
        Selection.Copy
    End If
    theTag = "< " & shp.Name & ">"
    endTag = "</" & shp.Name & ">"
    extract.Activate
    Selection.TypeText theTag
    Selection.Paste
    Selection.TypeText endTag & vbCrLf
    original.Activate
    shp.Select
    Selection.Bookmarks.Add ("temp")
    shp.Delete
    Selection.GoTo wdGoToBookmark, "temp"
    Selection.TypeText theTag & vbCrLf
    Selection.Bookmarks("temp").Delete
Next shp

Any help greatly appreciated!

Thanks,
Andy

[blue]Speak out against Human Rights violations in China/Tibet
[/blue]
 
Hi Andy,

This is quite an involved process. There are, simply put, two layers in a document - text and drawing. Shapes are in the drawing layer and their physical position is defined by an offset from an anchor.

When you delete a shape the physical position of that shape is (a) lost and (b) probably no longer useful as text will most likely move to fill in the gap (it depends on the text flow properties of the shape).

Also the Selection in the text layer is unconnected with the selection in the drawing layer so you must explicitly put it where you want it.

You must decide what sort of tags you want. Do you want shapes which could be placed roughly where the original shape was - but might end up askew if there were multiple shapes in close proximity. Or do you want tags in the text in which case a best guess is all you can really do; tags at the beginning (or end) of the anchored paragraph might work.

I'm just on my way out the door but if you say what you want I can try some code later - but, whatever, it won't be perfect.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
I knew it!
As always, you provide excellent advice, Tony!
[medal]

I didn't know of that different layer thing. Now that explains it all.
i cannot replace it with a shape, because that is the one and only reason I am doing this procedure after all: the docs will be further handled by a tool, which cannot handle shapes properly, especially not InlineShapes. Text frames, too, are a great problem.
That is why I only export the contents of the text frames, and later, I'll try to create a new one, importing the edited (translated) text.

Here's how I fixed the problem now:
Code:
For Each shp In original.Shapes
    shp.Select
    If shp.TextFrame.HasText Then
        shp.TextFrame.TextRange.Copy
    Else
        Selection.Copy
    End If
    theTag = "< " & shp.Name & ">"
    endTag = "</" & shp.Name & ">"
    extract.Activate
    Selection.TypeText theTag
    Selection.Paste
    Selection.TypeText endTag & vbCrLf
    original.Activate
    [b]Selection.Start = shp.Anchor.Start[/b]
    shp.Delete
    Selection.TypeText theTag & vbCrLf
Next shp[/quote]

This was all it took.
:-)

Cheers,
Andy

[blue]Speak out against Human Rights violations in China/Tibet
[URL unfurl="true"]http://www.thepetitionsite.com/takeaction/323661827[/URL]
[/blue]
 

Glad you're sorted. Armed with information it's so much easier to make a decision :)

If you want to be able to reformat the document on the other side, as it were, you might consider also adding some of the layout properties to the tag you include (or the other doc).

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Yep, already done that.
I'm already adding top, left, width and height info, as well as anchor position.

I'm currently thinking about writing an additional properties file containing all necessary info to each shape/inline shape, so I don't need to pack it all in the tag.
Then the tag's the id, and the prop file the properties database to it.

Still have to figure out some things though, because the shapes sometimes will paste into the new document, overlapping my tags. And a paste special as either shape, jpeg or enhanced metafile doesn't really help either. [sad]

Will take some more experimenting.

There is just too much information hidden behind each shape...

Thanks & Cheers,
Andy

[blue]Speak out against Human Rights violations in China/Tibet
[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top