Home > Software engineering >  Add space and return after inline shape
Add space and return after inline shape

Time:06-19

I was hoping someone could help me with a VBA code solution in microsoft word. I used a code found online to re-size all of the pictures in a word document to be the same size. This is listed below:

Sub Resize_All_Pictures()
'
' Resize_All_Pictures Macro
'
'
mytext = " "
Dim iShape As InlineShape

For Each iShape In ActiveDocument.InlineShapes
    With iShape
        .Width = InchesToPoints(2.21)
        .Height = InchesToPoints(2.21)
    End With
Next iShape

End Sub

This works perfectly as intended. However, I would like to add one space after each image and a return after each row of pictures(which will be three pictures in one row) but I am unsuccessful in doing so. The after code above image is what it looks like after running the code above. The Ultimate goal image is what I am looking for. Could anyone please help with this?

Thank you, Vognog

CodePudding user response:

You need to use the shape's Range object. If you add a counter you can then determine whether to add a space or a new paragraph.

Sub Resize_All_Pictures()
    '
    ' Resize_All_Pictures Macro
    '
    '
    Dim iShape As InlineShape
    Dim count As Long

    For Each iShape In ActiveDocument.InlineShapes
        With iShape
            .Width = InchesToPoints(2.21)
            .Height = InchesToPoints(2.21)
            count = count   1
            If count Mod 3 = 0 Then
                .Range.InsertAfter vbCr
            Else
                .Range.InsertAfter " "
            End If
        End With
    Next iShape

End Sub
  • Related