Word 2007 - Picture Visual Basic Code

M

Mary Fetsch

In Word 2007, I adjust the text wrapping around a picture by right-clicking
on the picture and then choosing Format Picture, Layout, Advanced, Through.
I'll be very grateful to anyone who can tell me the Visual Basic code for
this.

Mary Fetsch
 
J

Jay Freedman

In Word 2007, I adjust the text wrapping around a picture by right-clicking
on the picture and then choosing Format Picture, Layout, Advanced, Through.
I'll be very grateful to anyone who can tell me the Visual Basic code for
this.

Mary Fetsch

It can get a little complicated in code. A picture can be in line with
text, or it can be floating. In VBA, in-line pictures are one kind of
object and floating pictures are a completely different kind. Although
you can convert the kinds from one to the other, you can't just say
"fix this picture".

When you use the Format Picture dialog, it can do the conversion
silently and let you go from in-line to any one of the floating
variations. In code, you have to do something like this:

Sub demo()
If Selection.InlineShapes.Count > 0 Then
HandleInlineShape Selection.InlineShapes(1)
ElseIf Selection.ShapeRange.Count > 0 Then
HandleShape Selection.ShapeRange(1)
Else
MsgBox "Please select a picture first.", , _
"Wrong Selection"
End If
End Sub

Private Sub HandleInlineShape(ils As InlineShape)
Dim tempShp As Shape
Set tempShp = ils.ConvertToShape
HandleShape tempShp
End Sub

Private Sub HandleShape(shp As Shape)
shp.WrapFormat.Type = wdWrapThrough
End Sub

If you start out with an in-line picture (an InlineShape object),
first it gets passed to the HandleInlineShape macro, which converts it
to a floating shape and passes it to the HandleShape macro. If you
start out with a floating picture already (a Shape object), it gets
passed directly to the HandleShape macro. In either case, the final
step is to assign the desired wrapping type to it.
 
M

Mary Fetsch

Thank you SO much, Jay. I've really been struggling with this. Your macro
will be such a timesaver.
 

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