Class Rectangle (Word VBA)

The class Rectangle represents a portion of text or a graphic in a page. Use the Rectangle object and related methods and properties for programmatically defining page layout in a document. To use a Rectangle class variable it first needs to be instantiated, for example

For Each

Here is an example of processing the Rectangle items in a collection.


Dim lin As Line: Set lin = 
Dim shp As Rectangle
For Each shp In lin.Rectangles
	With shp
		
	End With
Next shp

Height

Returns a Long that represents the height of a rectangle, in pixels.


Dim shp As Rectangle: Set shp =  
Dim lngHeight As Long
lngHeight = shp.Height

Left

Returns a Long that represents the number of pixels from the left edge of the page to the left edge of a rectangle.


Dim shp As Rectangle: Set shp =  
Dim lngLeft As Long
lngLeft = shp.Left

Lines

Returns a Lines collection that represents the lines in a specified portion of text in a page.

Use the Lines collection and related objects and properties to programmatically define page layout in a document.


Dim objRectangle As Rectangle 
Dim objLines As Lines 
 
Set objRectangle = ActiveDocument.ActiveWindow _ 
 .Panes(1).Pages(1).Rectangles(1) 
 
If objRectangle.RectangleType = wdTextRectangle Then _ 
 Set objLines = objRectangle.Lines

Range

Returns a Range object that represents the portion of a document that is contained within a rectangle.


Dim shp As Rectangle: Set shp =  
Dim rngRange As Range
Set rngRange = shp.Range

RectangleType

Returns a WdRectangleType constant that represents the type for the specified rectangle. Here you can find possible values for WdRectangleType.

Rectangles in Microsoft Word are sections within a page in a document that contain specific types of information. Some sections are portions of text; others are shapes. The purpose of rectangles is to allow more control over programmatic page layout.


Dim objRectangle As Rectangle 
 
Set objRectangle = ActiveDocument.ActiveWindow _ 
 .Panes(1).Pages(1).Rectangles(1) 
 
If objRectangle.RectangleType = wdTextRectangle Then 
 objRectangle.Range.CheckSpelling 
End If

Top

Returns a Long that represents the number of pixels from the top of the page to the top of a rectangle.


Dim shp As Rectangle: Set shp =  
Dim lngTop As Long
lngTop = shp.Top

Width

Returns or sets a Long that represents the width, in points, of a rectangle.


Dim shp As Rectangle: Set shp =  
Dim lngWidth As Long
lngWidth = shp.Width