PDA

View Full Version : [SOLVED:] Setting WrapFormat on a picture in MS Word



carnahant
05-17-2017, 09:25 AM
I am looking for a solution to a repetitive task I have to perform. I find myself constantly having to manually set the wrapformat to "Top and Bottom" and set the AllowOverlap to false to achieve my goal.
I tried some code that I thought would work, but there is a problem:

Sub Picture_Wrap()

Dim myPicture As Word.Shape
Set myPicture = Selection.ShapeRange(1)

With myPicture.WrapFormat
.Type = wdWrapTopBottom
.AllowOverlap = False
End With
End Sub
Execution gets to the "Set myPicture" line and throws the following error:

Invalid procedure call or argument
Before I execute, I select and put the focus on the picture I pasted into the document.
Any help would be appreciated.
Thanks,
Tom

gmaxey
05-17-2017, 09:38 AM
Perhaps your picture is not a floating shape:


Sub Picture_Wrap()
Dim myPicture, MyShape
Set myPicture = Selection.InlineShapes(1)
Set MyShape = myPicture.ConvertToShape
With MyShape.WrapFormat
.Type = wdWrapTopBottom
.AllowOverlap = False
End With
End Sub

carnahant
05-17-2017, 10:09 AM
Wow! Thanks for the quick response! Your answer was right on! Excellent!

I was surprised that I didn't have to "type" the two object variables.

What is the difference between a "floating" shape and a "non-floating" shape?

Thanks,

Tom

carnahant
05-17-2017, 10:14 AM
I visited Greg's website. A fellow sailor. I spent 20 years as a Navy helicopter pilot. Thanks shipmate!

gmaxey
05-17-2017, 11:20 AM
Floating shapes "float" they are in a different storyrange and can be in front of text, behind text or the text wraps around them as is your case. Inlineshapes are inline with the text.

Thanks for your service!