Class HorizontalLineFormat (Word VBA)

The class HorizontalLineFormat represents horizontal line formatting. To use a HorizontalLineFormat class variable it first needs to be instantiated, for example


Dim hlf as HorizontalLineFormat
Set hlf = ActiveDocument.Range.InlineShapes(1).HorizontalLineFormat

Alignment

Returns or sets a WdHorizontalLineAlignment constant that represents the alignment for the specified horizontal line. Possible return values are wdHorizontalLineAlignCenter - Centered, wdHorizontalLineAlignLeft - Aligned to the left, wdHorizontalLineAlignRight - Aligned to the right.


ActiveDocument.Range.InlineShapes(1).HorizontalLineFormat.Alignment = wdHorizontalLineAlignCenter

NoShade

True if Microsoft Word draws the specified horizontal line without 3D shading.

You can only use this property with horizontal lines that are not based on an existing image file.


Selection.InlineShapes.AddHorizontalLineStandard 
ActiveDocument.InlineShapes(1) _ 
 .HorizontalLineFormat.NoShade = True

PercentWidth

Returns or sets the length of the specified horizontal line expressed as a percentage of the window width.

Setting this property also sets the WidthType property to wdHorizontalLinePercentWidth.


Selection.InlineShapes.AddHorizontalLineStandard 
ActiveDocument.InlineShapes(1) _ 
 .HorizontalLineFormat.PercentWidth = 50

WidthType

Returns or sets the width type for the specified HorizontalLineFormat object. Possible return values are wdHorizontalLineFixedWidth - Microsoft Word interprets the width (length) of the specified horizontal line as a fixed value (in points). This is the default value for horizontal lines added with the AddHorizontalLine method. Setting the Width property for the InlineShape object associated with a horizontal line sets the WidthType property to this value, wdHorizontalLinePercentWidth - Word interprets the width (length) of the specified horizontal line as a percentage of the screen width. This is the default value for horizontal lines added with the AddHorizontalLineStandard method. Setting the PercentWidth property on a horizontal line sets the WidthType property to this value.


Dim temp As InlineShape 
Set temp = _ 
 ActiveDocument.InlineShapes.AddHorizontalLineStandard 
MsgBox "AddHorizontalLineStandard - WidthType = " _ 
 & temp.HorizontalLineFormat.WidthType 
Set temp = _ 
 ActiveDocument.InlineShapes.AddHorizontalLine _ 
 ("C:\My Documents\ArtsyRule.gif") 
MsgBox "AddHorizontalLine - WidthType = " _ 
 & temp.HorizontalLineFormat.WidthType