Microsoft Office Tutorials and References
In Depth Information
A.3.1 The TextFrame Object
A.3.1 The TextFrame Object
Each Shape object has a text frame associated with it that holds any text associated with the object.
The TextFrame property returns this TextFrame object.
The TextFrame object has a Characters property that returns a Characters collection. This
collection can set the text in the text frame. For instance, the code in Example A-3 adds a
rectangle to the active sheet and also adds text to the rectangle and sets the alignment for the text
Example A-3. The AddRectangle Procedure
Sub AddRectangle()
With ActiveSheet.Shapes.AddShape(msoShapeRectangle, 10, 10, 200,
.Characters.Text = "This is a rectangle"
.HorizontalAlignment = xlHAlignCenter
.VerticalAlignment = xlVAlignCenter
End With
End Sub
A.3.2 The FillFormat Object
The FillFormat object sets various formatting for a Shape object. It is accessed using the Fill
property of the Shape object. Among the properties of the FillFormat object are the BackColor,
ForeColor, Pattern, and Visible properties. To set one of the color properties, we use the RGB
color model, as in the following example:
sh.Fill.ForeColor.RGB = RGB(0, 0, 255)
A.3.3 Examples
To illustrate the use of AutoShapes , Example A-4 inserts a dampened sine curve of small stars in
the drawing layer.
Example A-4. DrawSine2, to Generate a Dampened Sine Curve of Small Stars
Sub DrawSine2()
' Dampened sine wave of small stars
Const pi = 3.1416
Dim i As Integer
Dim x As Single, y As Single
Dim rng As Range ' For starting point
Dim n As Single ' Cycle length in inches
Dim k As Integer ' k stars
Dim ScaleY As Single ' Vertical scaling
Dim sSize As Single ' Star size
Dim sDamp1 As Single ' Dampening factor
Dim sDamp2 As Single ' Dampening factor
Dim cCycles As Integer ' Number of cycles
Dim sh As Shape
Dim StartLeft As Integer
Dim StartTop As Integer
' Starting position
StartLeft = ActiveCell.Left
Search JabSto ::

Custom Search