Edit InLineShape Programatically

G

Greg Maxey

Using Word2007 I can easily insert a picture (as an InLineShape) from a
file and then use Picture Tools>Format>Picture Effects>Shadow to add a
shadow and Size to resize the picture.

When I try to do that programatically with an InLineShape, the shadow
applied is like some sort of defualt shadow. The .forecolor, offsetX,
offsetY attributres are ignored.

Sub InsertImageAtSelection1()
Dim oILS As InlineShape
Dim y As Single
Set oILS = ActiveDocument.InlineShapes(1)
With oILS
y = CSng(.Height) / CSng(.Width)
.Width = InchesToPoints(2)
.Height = y * .Width
With .Shadow
.OffsetX = -5
.OffsetY = -3
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0.5
.Visible = msoCTrue
End With
End With
End Sub

If I first set the shadow.visible attribute on the InLineShape then covert
to a shape, I can apply the proper attributes. I then change back to an
InLineShape. Is this by design, a bug, or am I just off base on my methods?
Thanks,.

Sub InsertImageAtSelection2()
Dim oILS As InlineShape
Dim oShp As Shape
Dim y As Single
Set oILS = ActiveDocument.InlineShapes(1)
With oILS
y = CSng(.Height) / CSng(.Width)
.Width = InchesToPoints(2)
.Height = y * .Width
.Shadow.Visible = msoCTrue
End With
Set oShp = oILS.ConvertToShape
With oShp
With .Shadow
.OffsetX = -5
.OffsetY = -3
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0.5
.Visible = msoCTrue
End With
.ConvertToInlineShape
End With
End Sub




--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org


McCain/Palin '08 !!!
 
G

Greg Maxey

I found my problem.

The .Visible atribute has to be the first set. There are also a few other
setting that can be made. This works:

Dim oILS As InlineShape
Dim y As Single
Application.ScreenUpdating = False
'Insert the image selected in the gallery
Set oILS = ActiveDocument.InlineShapes.AddPicture(filename:=pName,
LinkToFile:=False, SaveWithDocument:=True, _
Range:=Selection.Range)
'Size image and set shadow (if shadow option selected).
With oILS
y = CSng(.height) / CSng(.width)
.width = InchesToPoints(2)
.height = y * .width
If bAddShadow Then
With .Shadow
.Visible = msoCTrue
.Blur = 4
.Size = 100
.Transparency = 0.5
.ForeColor.RGB = RGB(0, 0, 0)
.OffsetX = -5
.OffsetY = -3
End With
End If
End With
Application.ScreenUpdating = True





Greg said:
Using Word2007 I can easily insert a picture (as an InLineShape) from a
file and then use Picture Tools>Format>Picture Effects>Shadow
to add a shadow and Size to resize the picture.

When I try to do that programatically with an InLineShape, the shadow
applied is like some sort of defualt shadow. The .forecolor, offsetX,
offsetY attributres are ignored.

Sub InsertImageAtSelection1()
Dim oILS As InlineShape
Dim y As Single
Set oILS = ActiveDocument.InlineShapes(1)
With oILS
y = CSng(.Height) / CSng(.Width)
.Width = InchesToPoints(2)
.Height = y * .Width
With .Shadow
.OffsetX = -5
.OffsetY = -3
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0.5
.Visible = msoCTrue
End With
End With
End Sub

If I first set the shadow.visible attribute on the InLineShape then
covert to a shape, I can apply the proper attributes. I then change
back to an InLineShape. Is this by design, a bug, or am I just off
base on my methods? Thanks,.

Sub InsertImageAtSelection2()
Dim oILS As InlineShape
Dim oShp As Shape
Dim y As Single
Set oILS = ActiveDocument.InlineShapes(1)
With oILS
y = CSng(.Height) / CSng(.Width)
.Width = InchesToPoints(2)
.Height = y * .Width
.Shadow.Visible = msoCTrue
End With
Set oShp = oILS.ConvertToShape
With oShp
With .Shadow
.OffsetX = -5
.OffsetY = -3
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0.5
.Visible = msoCTrue
End With
.ConvertToInlineShape
End With
End Sub

--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org


McCain/Palin '08 !!!
 

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