Search code examples
vbams-word

Adding paragraphs after InlineShapes


Alright, this may be an easy question but I can't get the answer. I have a couple of pictures, I believe Word considers them 'InlineShapes', there are no paragraphs to separate them; I need to add a paragraph between the InlineShapes so when I go and do 'Convert Text to Table' I can use the Paragraphs as separations.

Here is part of the Code Sub Resize()

'Resize barcodes to fit in labels
Application.ScreenUpdating = False
Dim Shap As Shape
Dim IShape As InlineShape
Dim countshapes As Long
Dim countinlineshapes As Long

'Change Images into InlineShapes
Do
    countshapes = ActiveDocument.Shapes.Count
    For Each Shap In ActiveDocument.Shapes
        Shap.ConvertToInlineShape
    Next Shap

Loop Until countshapes = 0

'Resizes the pictures(now InlineShapes) and add paragraphs
For Each IShape In ActiveDocument.InlineShapes
    With IShape
        .Width = InchesToPoints(2)
        .Height = InchesToPoints(1.2)
        .Select
    End With
    'Here is where I thought the Paragraph would be added
    Selection.Paragraphs.Add
Next IShape

'Change Page Orientation
ActiveDocument.PageSetup.Orientation = wdOrientLandscape

'Create Table

Application.ScreenUpdating = True
End Sub

Thanks


Solution

  • No need to use Select- an InlineShape has a Range property, so something like this:

    Dim ilsRange as Word.Range
    
    Set ilsRange = IShape.Range
    ilsRange.InsertAfter vbCr
    

    Or you can make it shorter, as long as you don't need to do anything else with the Range:

    IShape.Range.InsertAfter vbCr