Font (object)

<< Click to Display Table of Contents >>

Font (object)

Access paths:

Application à Workbooks à Item à Sheets à Item à Range à Font

Application à Workbooks à ActiveSheet à Range à Font

Application à ActiveWorkbook à ActiveSheet à Range à Font

Application à ActiveSheet à Range à Font

Instead of "Range", you can also use other objects and properties that return a Range object: ActiveCell, Selection, Rows(n), Columns(n) and Cells(x, y). You can find examples of these access paths in the Range-Object.

 1  Description

The Font object describes the character formatting (font, text color, underline, etc.) of cells.

 2  Access to the object

The Font object is a child object of a Range object and represents the character formatting of cells in this range, corresponding to the Character formatting dialog box.

Example:

' Show the name of the font used in cell A1

MsgBox pm.ActiveSheet.Range("A1").Font.Name

 3  Properties, objects, collections and methods

Properties:

Name (default property)

Size

Bold

Italic

Underline

StrikeThrough

Superscript

Subscript

AllCaps

SmallCaps

PreferredSmallCaps

Blink

Color

ColorIndex

BColor

BColorIndex

Spacing

Pitch

 

Objects:

Application Application

Parent Range

Name (property)

Data type: String

Gets or sets the font name (as a string).

If the cells are formatted in different typefaces, an empty string will be returned.

Size (property)

Data type: Single

Gets or sets the font size in points (pt).

If the cells are formatted in different font sizes, the constant smoUndefined (9,999,999) will be returned.

Example:

' Set the font size of the currently selected cells to 10.3 pt

pm.ActiveSheet.Selection.Font.Size = 10.3

Bold (property)

Data type: Long

Gets or sets the character formatting "Boldface":

True: Boldface on

False: Boldface off

smoUndefined (only when reading): The cells are partly bold and partly not.

Italic (property)

Data type: Long

Gets or sets the character formatting "Italic":

True: Italic on

False: Italic off

smoUndefined (only when reading): The cells are partly italic and partly not.

Underline (property)

Data type: Long (PmUnderline)

Gets or sets the character formatting "Underline". The following values are allowed:

pmUnderlineNone        = 0 ' off

pmUnderlineSingle      = 1 ' single underline

pmUnderlineDouble      = 2 ' double underline

pmUnderlineWords       = 3 ' word underline

pmUnderlineWordsDouble = 4 ' double word underline

When you read this property and the cells are partly underlined and partly not, smoUndefined is returned.

StrikeThrough (property)

Data type: Long

Gets or sets the character formatting "Strike Through":

True: Strike through on

False: Strike through off

smoUndefined (only when reading): The cells are partly stroke through and partly not.

Superscript (property)

Data type: Long

Gets or sets the character formatting "Superscript":

True: Strike through on

False: Strike through off

smoUndefined (only when reading): The cells are partly superscripted and partly not.

Subscript (property)

Data type: Long

Gets or sets the character formatting "Subscript":

True: Strike through on

False: Strike through off

smoUndefined (only when reading): The cells are partly subscripted and partly not.

AllCaps (property)

Data type: Long

Gets or sets the character formatting "All caps":

True: All caps on

False: All caps off

smoUndefined (only when reading): Some of the cells are formatted in "All caps", some not.

SmallCaps (property)

Data type: Long

Gets or sets the character formatting "Small caps":

True: Small caps on

False: Small caps off

smoUndefined (only when reading): Some of the cells are formatted in "Small caps", some not.

PreferredSmallCaps (property)

Data type: Long

Gets or sets the character formatting "Small caps", but unlike the SmallCaps property, lets you choose the scale factor. The value 0 turns SmallCaps off, all other values represent the percental scale factor of the small capitals.

Example:

' Format the current cell in small capitals with 75% of size

pm.ActiveCell.Font.PreferredSmallCaps = 75

 

' Deactivate the SmallCaps formatting

pm.ActiveCell.Font.PreferredSmallCaps = 0

Blink (property)

Data type: Long

Gets or sets the character formatting "Blink" (obsolete):

True: Blink on

False: Blink off

smoUndefined (only when reading): The cells are partly blinking and partly not.

Color (property)

Data type: Long (SmoColor)

Gets or sets the foreground color of text as a "BGR" value (Blue-Green-Red triplet). You can either indicate an arbitrary value or use one of the pre-defined BGR color constants.

If the cells are formatted in different colors, the constant smoUndefined will be returned when you read this property.

ColorIndex (property)

Data type: Long (SmoColorIndex)

Gets or sets the foreground color of text as an index color. "Index colors" are the standard colors of PlanMaker, consecutively numbered from 0 for black to 15 for light gray. You may use the values shown in the Index colors table.

If the cells are formatted in different colors or in a color that is not an index color, the constant smoUndefined will be returned when you read this property.

Note: It is recommended to use the Color property (see above) instead of this one, since it is not limited to the standard colors but enables you to access the entire BGR color palette.

BColor (property)

Data type: Long (SmoColor)

Gets or sets the background color of text as a "BGR" value (Blue-Green-Red triplet). You can either indicate an arbitrary value or use one of the pre-defined BGR color constants.

If the cells are formatted in different colors, the constant smoUndefined will be returned when you read this property.

BColorIndex (property)

Data type: Long (SmoColorIndex)

Gets or sets the background color of text as an index color. "Index colors" are the standard colors of PlanMaker, consecutively numbered from 0 for black to 15 for light gray. You may use the values shown in the Index colors table.

If the cells are formatted in different colors or in a color that is not an index color, the constant smoUndefined will be returned when you read this property.

Note: It is recommended to use the BColor property (see above) instead of this one, since it is not limited to the standard colors but enables you to access the entire BGR color palette.

Spacing (property)

Data type: Long

Gets or sets the character spacing. The standard value is 100 (normal character spacing of 100%).

If you are reading this property and the cells are formatted in different character spacings, the constant smoUndefined will be returned.

Pitch (property)

Data type: Long

Gets or sets the character pitch. The standard value is 100 (normal character pitch of 100%).

If you are reading this property and the cells are formatted in different character pitches, the constant smoUndefined will be returned.

Note that some printers ignore changes to the character pitch for their internal fonts.

Application (pointer to object)

Data type: Object

Returns the Application object.

Parent (pointer to object)

Data type: Object

Returns the parent object, i.e. an object of the type Range.

Example for the Font object

In the following example, cells A1 to C3 will be formatted in Times New Roman, bold, 24 points.

Sub Main

 Dim pm as Object

 

 Set pm = CreateObject("PlanMaker.Application")

 pm.Visible = True

 

 With pm.ActiveSheet.Range("A1:C3")

                 .Font.Name = "Times New Roman"

                 .Font.Size = 24

                 .Font.Bold = True

 End With

 

 Set pm = Nothing

End Sub