picture/text box group bug?

S

sysdrk

I'm trying to use a text box below a picture to create a caption for
the picture. So I create the text box, align it just below the picture
but when I group the picture and text box, the text box gets centered
in the middle of the picture. However, if I single step through the
group command, the code works (the text box is kept under the picture).
Similarly, if I plant a breakpoint on the group command and then just
Continue when the breakpoint is reached the code works.

I have to presume this is a bug. Has anyone seen anything like this?
Know of any work around? This is Word 2003.

Denis

Here's the actual code:

' Make ShapeRange out of picture and text box, align text box with
center
' of picture, shift text box down to just below picture, then group
vertshift = (pictht + tbox.ShapeRange.Height) / 2
ActiveDocument.Shapes.Range(Array(pictname,
tbox.ShapeRange.Name)).Select
Set pictext = Selection
pictext.ShapeRange.Align msoAlignLefts, False
pictext.ShapeRange.Align msoAlignMiddles, False
tbox.ShapeRange.IncrementTop vertshift
pictext.ShapeRange.Group.Select
 
W

Word Heretic

G'day "(e-mail address removed)" <[email protected]>,

This project becomes drastically simpler by defining styles and
applying them. In your case, Body Text C (Body Text, centred) would be
perfect here.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


(e-mail address removed) reckoned:
 
S

sysdrk

I'm all in favor of simplifying this project but I'm afraid I don't
understand what is being suggested. How does Body Text C get a caption
under a picture?
 
W

Word Heretic

G'day "(e-mail address removed)" <[email protected]>,

If you defined a style to be centred, (eg Body Text C) you can just
apply the style to the picture and the following paragraph to have
them both centred.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


(e-mail address removed) reckoned:
 
S

sysdrk

OK, I understand how a style can center a picture and the following
paragraph. But what I want to do is have a picture with a caption
centered below the picture with both the picture/caption either left
adjust or right adjusted so that the text in the document flows around
the picture/caption (format picture/layout/square/right or left
horizontal adjustment).

I know how to do this manually and I already do this manually for a
picture alone. I've been trying to extend this to where I can have a
macro automatically place a caption below the picture and keep both the
picture/caption either right or left adjusted with text flowing around
the pair. This is easily done manually but not programmatically.

I did manage to get a macro to do this with the picture/caption (text
box) grouped but then discovered that Word converted the JPEG photo
into a GIF when the 2 are grouped and a GIF is exactly the wrong choice
for a photo. So I backed off the grouping and just tried to get the
macro to right/left adjust the pair ungrouped and that has eluded all
my attempts so far. I can't get the pair ungrouped both right adjusted
with text flowing around them.

Denis
 
D

David Sisson

Word may be running too fast for it's own good.

I searched for Sleep and found this suggestion from Jonathan West.

Quote:
Put this at the start of a module, after Option Explicit, but before
the
first Sub or Function


Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal
dwMilliseconds As Long)


Then you can have a delay in your code like this


Sleep 100 ' 100 ms pause

End Quote:

Put this before the group command and see it it helps.

Another suggestion added a DoEvents before the Sleep command.

DoEvents
Sleep 100
 
W

Word Heretic

G'day "(e-mail address removed)" <[email protected]>,

Ah ha! Yes, I see your problem.

OK, first up, you are trying to programmatically muck with floating
shapes. I _always_ avoid this. To be blunt, Word sux BIG TIME at using
floaters, and then from VBA it gets even worse than that!

Some ideas you can play with (normally I just avoid the text wrap
requirement):

Using a frame defined style for both picture and caption.

Not grouping, have a floating pik, then insert a floating text box of
the same width, left and whose top is the bottom of the pik + say 6.
This should leave your original pic format intact.

Use PNG instead of JPG - may keep its format.



Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


(e-mail address removed) reckoned:
 
S

sysdrk

First, I played around with the suggestion to try using sleep to slow
Word down. This looked like a good idea but I wasn't able to make it
work. However, this was largely academic since my original idea of
grouping picture/caption proved unworkable once I found Word converted
the .jpg to .gif. Still it's a good idea to keep in mind for potential
future workaround, which is why I played with it.

Next,
OK, first up, you are trying to programmatically muck with floating
shapes. I _always_ avoid this. To be blunt, Word sux BIG TIME at using
floaters, and then from VBA it gets even worse than that!

This is the conclusion I came to so it's nice to see it confirmed by
someone else.
Not grouping, have a floating pik, then insert a floating text box of
the same width, left and whose top is the bottom of the pik + say 6.
This should leave your original pic format intact.

This (not grouping) is what I tried next and I thought I would be able
to get that to work. Unfortunately, I have found no way to get both
picture & caption left or right adjusted with text wrapping (they get
placed side-by-side). And I have tried a variety of different
attempts, hoping that one might at least work accidentally but no luck.
So I think this just confirms again the previous observation about
trying to work with floating shapes.

I haven't tried the PNG vs JPG. That might be worthwhile if I were
starting from scratch. Unfortunately, I have a bunch of documents (web
pages) with existing JPGs that I was hoping to be able to go in and
simply caption with the aid of a macro. Doesn't look like this is
going to work unless I'm willing to do the final alignment manually. I
could still use the macro to create the text box below the picture but
that looks like the best I may be able to do.

Thanks for all the suggestions.

Denis
 

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