Adding a shadow to an inline picture

W

William Meisheid

I can manually add a shadow to an inline picture by selecting the picture and
using the Drawing toolbar, but when I record that action in a macro Word
writes into the code:

Selection.ShapeRange(1).Shadow.Type = msoShadow6 'the shadow type I chose

However, if I try to run the macro I get an error because Shadow is not a
property of ShapeRange, even though that is what the record macro tool saw
happen.

How do I code something that will allow me to programmatically add a shadow
to an inline picture?
 
J

Jay Freedman

As I wrote in
http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm, the
recorder sometimes records stuff that "just ain't so", and this is one
of those cases.

The only way to get the same effect in a macro that you get with one
button click in the UI is to convert the inline shape to a Shape
object, apply the shadow to that, and then convert back.

Dim oShp As Shape
Set oShp = Selection.InlineShapes(1).ConvertToShape
oShp.Shadow.Type = msoShadow6
oShp.ConvertToInlineShape

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Thu, 18 Jan 2007 15:30:02 -0800, William Meisheid <William
 
J

Jay Freedman

Incidentally, although in Word 2003 the statement

Selection.InlineShapes(1).Shadow.Type = msoShadow6

causes an error "Method or data member not found", it works perfectly
in Word 2007. I guess now and then a bug fix actually slips in. :)

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
J

Jay Freedman

After some experimenting, I find that Word will apply a shadow to an inline
..jpg picture, but not to most .bmp or .gif pictures (although I did find one
..gif that worked). A given picture will or won't show a shadow, regardless
of whether it's inline or floating, and regardless of whether I use a manual
method or a macro.

This doesn't seem to be anything to do with the macro itself or with VBA.
Upon inserting the inline picture, if I go to the Drawing toolbar and pop up
the Shadow menu, the options may be enabled or disabled depending on what
kind of graphic is selected. After converting the picture to Square or
Top/Bottom, the Shadow menu's behavior is still the same. If shadows are
disabled, the macro doesn't appear to do anything -- but neither does the
UI.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

Jay Freedman

OK, I located a .png graphic (I don't use them very often) and tried the
macro on it. It works without any problems.

It seems we're missing some other circumstance or variable that determines
when the shadow appears. I don't know what that might be -- I can't explain
the problem with .gif and .bmp, either, so that's not so surprising.

Is there anything non-default set in the properties of the paragraph or its
style? Does the graphic have transparency set, or has it been edited in Word
in any way? Does the same graphic behave the same way in a new blank
document, or in a document based on a different template?

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
W

William Meisheid

Thanks for suggesting I look at a default document. It worked. Now I need to
debug why it doesn't work on my template.

Nothing like missing the obvious. Thanks for your patience. I will let you
know what I find out, if anything... ;-)

Regards,
William Meisheid
 
J

Jay Freedman

Best of luck! If you do find something, I'll be interested to hear about it.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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