Find the text box below an image

I

Ildhund

My macro to extract images from a Publisher file (see
) is working fine, thanks to Ed,
for cases where the image is grouped with a text box containing the caption.
I can use part of the caption as FileName and all of it as a Comment in the
File Properties.

However, while all images have their caption in a text box beneath the
picture, this pair of objects is not always grouped. When I cycle through
the objects on a page, I can see that sometimes the caption was placed first
and sometimes the image. So, having selected an image to work with, how do I
then select the text box immediately below it on the page? I can locate the
text box roughly by starting at .Top and .Left, Increment by .Height + 5 and
..Width/2, but how do I select the object at that position on the page, given
that there is only one?
 
E

Ed Bennett

Ildhund said:
So, having selected an image to work with, how do I
then select the text box immediately below it on the page? I can locate the
text box roughly by starting at .Top and .Left, Increment by .Height + 5 and
.Width/2, but how do I select the object at that position on the page, given
that there is only one?

Iterate through all the text boxes on the page, and check which one has
the correct values of Top and Left?

A way to prevent this difficulty in future would be to add a pair of
tags to each shape pair with a unique ID. For example, add a tag called
"associateID" with a unique identifier as its value, and another tag
with its name as the unique identifier, to both the picture and the text
box. Then you can easily find the associated text box for a picture and
vice-versa using
ThisDocument.FindShapesByTag(aPicture.Tags("associateID").Value)
 
I

Ildhund

Ed Bennett wrote...
Iterate through all the text boxes on the page, and check which one has
the correct values of Top and Left?

Good idea, thanks. Because the text boxes aren't precisely placed, I'll have
to introduce some margin of error and hope I hit the right one. And
*another* iteration is going to slow this down even more, but that's not a
problem (yet!).
A way to prevent this difficulty in future would be to add a pair of tags
to each shape pair with a unique ID. For example, add a tag called
"associateID" with a unique identifier as its value, and another tag with
its name as the unique identifier, to both the picture and the text box.
Then you can easily find the associated text box for a picture and
vice-versa using
ThisDocument.FindShapesByTag(aPicture.Tags("associateID").Value)

I can't imagine ever having to do this again, so I hope there is no "in
future.

Thanks again.
 
E

Ed Bennett

Ildhund said:
Good idea, thanks. Because the text boxes aren't precisely placed, I'll have
to introduce some margin of error and hope I hit the right one. And
*another* iteration is going to slow this down even more, but that's not a
problem (yet!).

Once the code's written, surely you'll only have to iterate through once?
 
I

Ildhund

Ed Bennett wrote...
Once the code's written, surely you'll only have to iterate through once?

Sure, but there are dozens of pages in each of dozens of files and dozens of
pictures on each page. For each page I have to cycle through the objects; if
it's a group, copy it to This document, ungroup it and check that it's one
picture + one text box and process them. If it's not a group, cycle through
the text boxes to find the right one, extract its text, then copy the
picture to This document...

OK, it's not these iterations that are taking time; it's largely
SaveAsPicture, but the resizing is not instantaneous, either, even with
screen updating off. I'll cope. I understand all the original image files
have been jettisoned because "they're all in the Publisher files". Ha hum.
 

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