VBA Code


Different Types of Shapes

Shapes can be classified to be any of the following:

  • Pictures

  • OLE Objects

  • AutoShapes

  • FreeForms

  • ActiveX controls.


Shapes can appear in 2 places

  • In the Drawing Layer

  • In the Text Layer - any shapes in this layer are referred to as inline shapes.


What is a Shape ?

A shape object is an object that is in the drawing layer of the document.
They are anchored to a range of text but are free-floating and can be positioned anywhere on the page.
The shape object is a member of the Shapes collection, which includes all the shapes in the main story of a document or in all the headers and footers of a document.


There are two objects that represent shapes.
1) The shapes collection which represents all the shapes in the document
2) The shaperange collection which represents a subset of all the shapes, typically for the current selection.


Dim objShape As Shape 
   
   For Each objShape In ActiveDocument.Shapes
       With objShape
           If .Type = msoShapeType.msoLinkedOLEObject Then
               .LinkFormat.Update
               .LinkFormat.BreakLink
           End If
       End With
   Next shapeLoop

Converting Shapes and InlineShapes

You can use the ConvertToInlineShape and ConvertToShape methods to convert shapes from one type to the other.
You can only convert pictures, OLE Objects and Active X objects to inline shapes.
This code converts all the inline shapes to actual shapes ??

Dim objShape As Shape 
For Each objShape In ActiveDocument.InlineShapes
   objShape.ConvertToShape
Next objShape

Selection.PasteSpecial Placement:=wdInLine 


The following line generates an error if track changes is on.

Shapes(2).ConvertToInlineShape 


Sub Macro1() 
    Dim oInlineShape As InlineShape

    For Each oInlineShape In Selection.InlineShapes
       oInlineShape.SoftEdge.Type = msoSoftEdgeType2
    Next oInlineShape
    
End Sub


© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext