Picture text wrapping format macro

I have tried to create a macro in Word 2007 to format the text wrapping of pictures to TopandBottom.  I'm not very knowlegeable about VBA code, but using examples and help, I've come up with the following.

Sub PictureFormat()

Set myDocument = ActiveDocument
With myDocument.Shapes(1).PictureFormat
Selection.ShapeRange.WrapFormat.Type = wdWrapTopandbottom
.RelativeVerticalPosition = _
 wdRelativeVerticalPositionParagraph
 .Left = CentimetersToPoints(3)
 .Right = CentimetersToPoints(3)
 .Top = CentimetersToPoints(2)
 .bottom = CentimetersToPoints(2)
 .WrapFormat.DistanceLeft = 0.2
 .WrapFormat.DistanceRight = 0.2
 End With

End Sub

There may be code that isn't necessary and I am sure I am missing some essential code.  All I want to be able to do is click on a picture, hit a macro that changes the text wrapping to Top and Bottom so that any text will appear under the picture.  If anyone can help me, I would be sooo grateful.  I've tried really hard to figure out VBA code, but I'm lost.

Thank you in advance

Danielle

Answer
Answer

Sorry about that. Questions sometimes "get lost" if they aren't seen by someone with the appropriate knowledge before they scroll off the first page or two.

The macro you posted has a few problems. The main one is that the constant you used in the .WrapFormat.Type assignment shouldn't have the "and" in the middle; it's just wdWrapTopBottom.

I think what you want is the macro below. It might need some tweaks to position the picture where you want it.

Sub PictureFormat()
    If Selection.ShapeRange.Count = 0 Then
        If Selection.InlineShapes.Count = 1 Then
            Selection.InlineShapes(1).ConvertToShape
        Else
            MsgBox "Select a picture first.", , "Oops!"
            Exit Sub
        End If
    End If
    
    With Selection.ShapeRange(1)
        .Top = CentimetersToPoints(0.5)
        .RelativeVerticalPosition = _
            wdRelativeVerticalPositionParagraph
        .Left = CentimetersToPoints(3)
        .RelativeHorizontalPosition = _
            wdRelativeHorizontalPositionColumn
        With .WrapFormat
            .Type = wdWrapTopBottom
            .DistanceTop = CentimetersToPoints(0.2)
            .DistanceBottom = CentimetersToPoints(0.2)
        End With
    End With
End Sub

_____________________________
https://jay-freedman.info

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated May 21, 2023 Views 4,336 Applies to: