Format related procedures in class Shape (Word VBA)

This page presents procedures from class Shape related to the theme Format: BackgroundStyle, GraphicStyle, HeightRelative, LayoutInCell, LinkFormat, OLEFormat, ScaleHeight, ScaleWidth, ShapeStyle, Visible, WidthRelative, WrapFormat, ShapeRange.BackgroundStyle, ShapeRange.GraphicStyle, ShapeRange.HeightRelative, ShapeRange.LayoutInCell, ShapeRange.ScaleHeight, ShapeRange.ScaleWidth, ShapeRange.ShapeStyle, ShapeRange.Visible, ShapeRange.WidthRelative and ShapeRange.WrapFormat

BackgroundStyle

Sets or returns the background style of the specified shape.

ActiveDocument.Background.BackgroundStyle =

GraphicStyle

Returns or sets an MsoGraphicStyleIndex constant that represents the style of an SVG graphic.

Dim myShape As Shape 
 
Set myShape = ActiveDocument.Shapes(1) 
 
myShape.GraphicStyle = msoGraphicStylePreset22

HeightRelative

Returns or sets a Single that represents the percentage of the relative height of a shape.

Use this property with the RelativeVerticalSize property. When set to wdShapeSizeRelativeNone (-999999) (see the WdShapeSizeRelative enumeration), this property should be ignored because the shape does not use percent sizing. The height is solely determined by the Height property.

ActiveDocument.Background.HeightRelative =

LayoutInCell

Returns a Long that represents whether a shape in a table is displayed inside or outside the table.

True indicates that a specified picture is displayed inside the table. False indicates that a specified picture is displayed outside the table. The LayoutInCell property corresponds to the Layout in table cell option in the Advanced Layout dialog box for picture formatting.

ActiveDocument.Shapes(1).LayoutInCell = False

LinkFormat

Returns a LinkFormat object that represents the link options of a shape that is linked to a file. Read/only.

Set iShape = ActiveDocument.InlineShapes _ 
 .AddPicture(FileName:="C:\windows\Tiles.bmp", _ 
 LinkToFile:=True, SaveWithDocument:=False, _ 
 Range:=Selection.Range) 
MsgBox iShape.LinkFormat.SourceName

OLEFormat

Returns an OLEFormat object that represents the OLE characteristics (other than linking) for the specified shape, inline shape, or field.

For Each s In ActiveDocument.Shapes 
 If s.Type = msoLinkedOLEObject Then 
 If s.OLEFormat.ProgID = "Excel.Sheet" Then 
 s.LinkFormat.AutoUpdate = True 
 End If 
 End If 
Next

ScaleHeight

Scales the height of the shape by a specified factor.

For pictures and OLE objects, you can indicate whether you want to scale the shape relative to the original size or relative to the current size. Shapes other than pictures and OLE objects are always scaled relative to their current height.

Syntax : expression.ScaleHeight (Factor, RelativeToOriginalSize, Scale)

Set myDocument = ActiveDocument 
For Each s In myDocument.Shapes 
 Select Case s.Type 
 Case msoEmbeddedOLEObject, msoLinkedOLEObject, _ 
 msoOLEControlObject, _ 
 msoLinkedPicture, msoPicture 
 s.ScaleHeight 1.75, True 
 s.ScaleWidth 1.75, True 
 Case Else 
 s.ScaleHeight 1.75, False 
 s.ScaleWidth 1.75, False 
 End Select 
Next

Arguments

The following arguments are required:

Factor (Single) - Specifies the ratio between the height of the shape after you resize it and the current or original height. For example, to make a rectangle 50 percent larger, specify 1.5 for this argument.

RelativeToOriginalSize (Office.MsoTriState) - True to scale the shape relative to its original size. False to scale it relative to its current size. You can specify True for this argument only if the specified shape is a picture or an OLE object.

The following argument is optional

Scale (Office.MsoScaleFrom) - The part of the shape that retains its position when the shape is scaled.

ScaleWidth

Scales the width of the shape by a specified factor.

For pictures and OLE objects, you can indicate whether you want to scale the shape relative to the original size or relative to the current size. Shapes other than pictures and OLE objects are always scaled relative to their current width.

Syntax : expression.ScaleWidth (Factor, RelativeToOriginalSize, Scale)

Set myDocument = ActiveDocument 
For Each s In myDocument.Shapes 
 Select Case s.Type 
 Case msoEmbeddedOLEObject, msoLinkedOLEObject, _ 
 msoOLEControlObject, _ 
 msoLinkedPicture, msoPicture 
 s.ScaleHeight 1.75, True 
 s.ScaleWidth 1.75, True 
 Case Else 
 s.ScaleHeight 1.75, False 
 s.ScaleWidth 1.75, False 
 End Select 
Next

Arguments

The following arguments are required:

Factor (Single) - Specifies the ratio between the width of the shape after you resize it and the current or original width. For example, to make a rectangle 50 percent larger, specify 1.5 for this argument.

RelativeToOriginalSize (Office.MsoTriState) - True to scale the shape relative to its original size. False to scale it relative to its current size. You can specify True for this argument only if the specified shape is a picture or an OLE object.

The following argument is optional

Scale (Office.MsoScaleFrom) - The part of the shape that retains its position when the shape is scaled.

ShapeStyle

Returns or sets the shape style for the specified shape.

Dim myShape As Shape 
 
Set myShape = ActiveDocument.Shapes(1) 
 
myShape.ShapeStyle = msoLineStylePreset12

Visible

True if the specified object, or the formatting applied to it, is visible.

FSome methods and properties may be unavailable if the Visible property is False.

Set myDoc = Documents.Add 
Selection.TypeText Text:="This is some sample text." 
With myDoc 
 .Shapes.AddShape msoShapeRectangle, 200, 70, 150, 60 
 .Shapes(1).Visible = False 
 .PrintOut 
 .Shapes(1).Visible = True 
End With

WidthRelative

Returns or sets a Single that represents the relative width of a shape.

Use this property with the RelativeVerticalSize property. When set to wdShapeSizeRelativeNone (-999999) (see the WdShapeSizeRelative enumeration), this property should be ignored because the shape does not use percent sizing. The width is solely determined by the Width property.

ActiveDocument.Background.WidthRelative =

WrapFormat

Returns a WrapFormat object that contains the properties for wrapping text around the specified shape.

Set myOval = _ 
 ActiveDocument.Shapes.AddShape(msoShapeOval, 36, 36, 90, 50) 
With myOval.WrapFormat 
 .Type = wdWrapSquare 
 .Side = wdWrapBoth 
 .DistanceTop = InchesToPoints(0.1) 
 .DistanceBottom = InchesToPoints(0.1) 
 .DistanceLeft = InchesToPoints(0.1) 
 .DistanceRight = InchesToPoints(0.1) 
End With

ShapeRange.BackgroundStyle

Sets or returns the background style of the shapes in the specified shape range.

Dim sre As ShapeRange: Set sre =  
sre.BackgroundStyle =

ShapeRange.GraphicStyle

Returns or sets an MsoGraphicStyleIndex constant that represents the style of a shape range containing one or more SVG graphics.

Dim sre As ShapeRange: Set sre =  
sre.GraphicStyle =

ShapeRange.HeightRelative

Returns or sets a Single that represents the percentage of the target shape to which the range of shapes is sized.

Use this property with the RelativeVerticalSize property. When set to wdShapeSizeRelativeNone (-999999) (see the WdShapeSizeRelative enumeration), this property should be ignored because the shape does not use percent sizing. The height is solely determined by the Height property.

Dim sre As ShapeRange: Set sre =  
sre.HeightRelative =

ShapeRange.LayoutInCell

Returns a Long that represents whether a shape in a table is displayed inside the table or outside the table.

The LayoutInCell property corresponds to the Layout in table cell option in the Advanced Layout dialog box for picture formatting. True indicates that a specified picture is displayed within the table. False indicates that a specified picture is displayed outside the table.

Dim sre As ShapeRange: Set sre =  
sre.LayoutInCell =

ShapeRange.ScaleHeight

Scales the height of a range of shapes by a specified factor.

For pictures and OLE objects, you can indicate whether you want to scale the shape relative to the original size or relative to the current size. Shapes other than pictures and OLE objects are always scaled relative to their current height.

Syntax : expression.ScaleHeight (Factor, RelativeToOriginalSize, Scale)

Dim sre As ShapeRange: Set sre =  
sre.ScaleHeight Factor:=, RelativeToOriginalSize:=msoTrue

Arguments

The following arguments are required:

Factor (Single) - Specifies the ratio between the height of the shape after you resize it and the current or original height. For example, to make a rectangle 50 percent larger, specify 1.5 for this argument.

RelativeToOriginalSize (Office.MsoTriState) - True to scale the shape relative to its original size. False to scale it relative to its current size. You can specify True for this argument only if the specified shape is a picture or an OLE object.

The following argument is optional

Scale (Office.MsoScaleFrom) - The part of the shape that retains its position when the shape is scaled.

ShapeRange.ScaleWidth

Scales the width of a shape by a specified factor.

For pictures and OLE objects, you can indicate whether you want to scale the range of shapes relative to the original size or relative to the current size. Shapes other than pictures and OLE objects are always scaled relative to their current width.

Syntax : expression.ScaleWidth (Factor, RelativeToOriginalSize, Scale)

Dim sre As ShapeRange: Set sre =  
sre.ScaleWidth Factor:=, RelativeToOriginalSize:=msoTrue

Arguments

The following arguments are required:

Factor (Single) - Specifies the ratio between the width of the shape after you resize it and the current or original width. For example, to make a rectangle 50 percent larger, specify 1.5 for this argument.

RelativeToOriginalSize (Office.MsoTriState) - True to scale the shape relative to its original size. False to scale it relative to its current size. You can specify True for this argument only if the specified shape is a picture or an OLE object.

The following argument is optional

Scale (Office.MsoScaleFrom) - The part of the shape that retains its position when the shape is scaled.

ShapeRange.ShapeStyle

Returns or sets the shape style for the shapes in the specified shape range.

Dim sre As ShapeRange: Set sre =  
sre.ShapeStyle =

ShapeRange.Visible

True if the specified object, or the formatting applied to it, is visible.

Some methods and properties may be unavailable if the Visible property is False.

Dim sre As ShapeRange: Set sre =  
sre.Visible =

ShapeRange.WidthRelative

Returns or sets a Single that represents the relative width of a range of shapes.

Use this property with the RelativeHorizontalSize property. When set to wdShapeSizeRelativeNone (-999999) (see the WdShapeSizeRelative enumeration), this property should be ignored because the shape does not use percent sizing. The width is solely determined by the Width property.

Dim sre As ShapeRange: Set sre =  
sre.WidthRelative =

ShapeRange.WrapFormat

Returns a WrapFormat object that contains the properties for wrapping text around the specified range of shapes.

Dim sre As ShapeRange: Set sre =  
Dim wftWrapFormat As WrapFormat
Set wftWrapFormat = sre.WrapFormat