Professional Documents
Culture Documents
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Remarks
Theres no singular Area object; individual members of the Areas collection are Range objects. The Areas
collection contains one Range object for each discrete, contiguous range of cells within the selection. If the
selection contains only one area, the Areas collection contains a single Range object that corresponds to that
selection.
Example
Use the Areas property to return the Areas collection. The following example clears the current selection if it
contains more than one area.
VBA
If Selection.Areas.Count <> 1 Then Selection.Clear
Use Areas(index), where index is the area index number, to return a single Range object from the collection. The
index numbers correspond to the order in which the areas were selected. The following example clears the first
area in the current selection if the selection contains more than one area.
VBA
If Selection.Areas.Count <> 1 Then
Selection.Areas(1).Clear
End If
Some operations cannot be performed on more than one area in a selection at the same time; you must loop
through the individual areas in the selection and perform the operations on each area separately. The following
example performs the operation named "myOperation" on the selected range if the selection contains only one
area; if the selection contains multiple areas, the example performs myOperation on each individual area in the
selection.
VBA
Set rangeToUse = Selection
If rangeToUse.Areas.Count = 1 Then
myOperation rangeToUse
Else
For Each singleArea in rangeToUse.Areas
myOperation singleArea
Next
End If
Properties
Name
Application
Count
Creator
Item
Parent
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
Example
This example displays a message about the application that created myObject.
VBA
Set myObject = ActiveWorkbook
If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
Areas.Count Property (Excel)
Office 2013 and later
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Long value that represents the number of objects in the collection.
Syntax
expression .Count
Example
This example displays the number of columns in the selection on Sheet1. The code also tests for a multiple-area
selection; if one exists, the code loops on the areas of the multiple-area selection.
VBA
Sub DisplayColumnCount()
Dim iAreaCount As Integer
Dim i As Integer
Worksheets("Sheet1").Activate
iAreaCount = Selection.Areas.Count
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
Remarks
If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Item(Index)
Parameters
Name Required/Optional Data Type Description
Example
This example clears the first area in the current selection if the selection contains more than one area.
VBA
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Parent
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Contains Microsoft Excel AutoCorrect attributes (capitalization of names of days, correction of two initial capital
letters, automatic correction list, and so on).
Example
Use the AutoCorrect property to return the AutoCorrect object. The following example sets Microsoft Excel to
correct words that begin with two initial capital letters.
VBA
With Application.AutoCorrect
.TwoInitialCapitals = True
.ReplaceText = True
End With
AutoCorrect.AddReplacement Method (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Adds an entry to the array of AutoCorrect replacements.
Syntax
Parameters
Data
Name Required/Optional Description
Type
Return Value
Variant
Example
This example substitutes the word "Temp." for the word "Temperature" in the array of AutoCorrect replacements.
VBA
With Application.AutoCorrect
.AddReplacement "Temperature", "Temp."
End With
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
VBA
Set myObject = ActiveWorkbook
If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
A Boolean value indicating whether automatic expansion is enabled for lists. When you type in a cell of an empty
row or column next to a list, the list will expand to include that row or column if automatic expansion is enabled.
Read/write Boolean.
Syntax
expression .AutoExpandListRange
Example
The following example enables automatic expansion of lists when typing in adjacent rows or columns.
VBA
Sub SetAutoExpand
Application.AutoCorrect.AutoExpandListRange = TRUE
End Sub
AutoCorrect.AutoFillFormulasInLists Property
(Excel)
Office 2013 and later
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Affects the creation of calculated columns created by automatic fill-down lists. Read/write Boolean.
Syntax
expression .AutoFillFormulasInLists
Remarks
The property does not affect existing calculated columns or calculated columns created where auto-fill did not
occur.
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
True if the first letter of day names is capitalized automatically. Read/write Boolean.
Syntax
expression .CapitalizeNamesOfDays
Example
This example sets Microsoft Excel to capitalize the first letter of the names of days.
VBA
With Application.AutoCorrect
.CapitalizeNamesOfDays = True
.ReplaceText = True
End With
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
True if Microsoft Excel automatically corrects accidental use of the CAPS LOCK key. Read/write Boolean.
Syntax
expression .CorrectCapsLock
Example
This example enables Microsoft Excel to automatically correct accidental use of the CAPS LOCK key.
VBA
Application.AutoCorrect.CorrectCapsLock = True
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
True if Microsoft Excel automatically corrects sentence (first word) capitalization. Read/write Boolean.
Syntax
expression .CorrectSentenceCap
Example
This example enables Microsoft Excel to automatically correct sentence capitalization.
VBA
Application.AutoCorrect.CorrectSentenceCap = True
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
Remarks
If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .DeleteReplacement(What)
Parameters
Data
Name Required/Optional Description
Type
The text to be replaced, as it appears in the row to be deleted from the array
What Required String of AutoCorrect replacements. If this string doesn't exist in the array of
AutoCorrect replacements, this method fails.
Return Value
Variant
Example
This example removes the word "Temperature" from the array of AutoCorrect replacements.
VBA
With Application.AutoCorrect
.DeleteReplacement "Temperature"
End With
AutoCorrect.DisplayAutoCorrectOptions Property
(Excel)
Office 2013 and later
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Allows the user to display or hide the AutoCorrect Options button. The default value is True. Read/write Boolean.
Syntax
expression .DisplayAutoCorrectOptions
Remarks
The DisplayAutoCorrectOptions property is a Microsoft Office-wide setting. Changing this property in
Microsoft Excel will affect the other Office applications also.
In Excel the AutoCorrect Options button only appears when a hyperlink is automatically created.
Example
This example determines if the AutoCorrect Options button can be displayed and notifies the user.
VBA
Sub CheckDisplaySetting()
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Parent
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .ReplacementList(Index)
Parameters
Data
Name Required/Optional Description
Type
Remarks
If Index is not specified, this method returns a two-dimensional array. Each row in the array contains one
replacement, as shown in the following table.
Column Contents
Example
This example searches the replacement list for "Temperature" and displays the replacement entry if it exists.
VBA
repl = Application.AutoCorrect.ReplacementList
For x = 1 To UBound(repl)
If repl(x, 1) = "Temperature" Then MsgBox repl(x, 2)
Next
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
True if text in the list of AutoCorrect replacements is replaced automatically. Read/write Boolean.
Syntax
expression .ReplaceText
Example
This example turns off automatic text replacement.
VBA
With Application.AutoCorrect
.CapitalizeNamesOfDays = True
.ReplaceText = False
End With
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
True if words that begin with two capital letters are corrected automatically. Read/write Boolean.
Syntax
expression .TwoInitialCapitals
Example
This example sets Microsoft Excel to correct words that begin with two capital letters.
VBA
With Application.AutoCorrect
.TwoInitialCapitals = True
.ReplaceText = True
End With
utoFilter Object (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Note
When using AutoFilter with dates, the format should be consistent with English date separators ("/") instead of
local settings ("."). A valid date would be "2/2/2007", whereas "2.2.2007" is invalid.
Note
Working with objects (e g Interior Object) requires adding a reference to an object. You will find more
information about assigning an Object reference to a variable or property in the Set Statement.
Example
Use the AutoFilter property to return the AutoFilter object. Use the Filters property to return a collection of
individual column filters. Use the Range property to return the Range object that represents the entire filtered
range. The following example stores the address and filtering criteria for the current filtering and then applies new
filters.
VBA
Dim w As Worksheet
Dim filterArray()
Dim currentFiltRange As String
Sub ChangeFilters()
Set w = Worksheets("Crew")
With w.AutoFilter
currentFiltRange = .Range.Address
With .Filters
ReDim filterArray(1 To .Count, 1 To 3)
For f = 1 To .Count
With .Item(f)
If .On Then
filterArray(f, 1) = .Criteria1
If .Operator Then
filterArray(f, 2) = .Operator
filterArray(f, 3) = .Criteria2
End If
End If
End With
Next
End With
End With
w.AutoFilterMode = False
w.Range("A1").AutoFilter field:=1, Criteria1:="S"
End Sub
To create an AutoFilter object for a worksheet, you must turn autofiltering on for a range on the worksheet either
manually or using the AutoFilter method of the Range object. The following example uses the values stored in
module-level variables in the previous example to restore the original autofiltering to the Crew worksheet.
VBA
Sub RestoreFilters()
Set w = Worksheets("Crew")
w.AutoFilterMode = False
For col = 1 To UBound(filterArray(), 1)
If Not IsEmpty(filterArray(col, 1)) Then
If filterArray(col, 2) Then
w.Range(currentFiltRange).AutoFilter field:=col, _
Criteria1:=filterArray(col, 1), _
Operator:=filterArray(col, 2), _
Criteria2:=filterArray(col, 3)
Else
w.Range(currentFiltRange).AutoFilter field:=col, _
Criteria1:=filterArray(col, 1)
End If
End If
Next
End Sub
Note
When using AutoFilter with dates, the format should be consistent with English date separators ("/") instead of
local settings ("."). A valid date would be "2/2/2007", whereas "2.2.2007" is invalid.
Methods
Name
ApplyFilter
ShowAllData
Properties
Name
Application
Creator
FilterMode
Filters
Parent
Range
Sort
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
Example
This example displays a message about the application that created myObject.
VBA
Set myObject = ActiveWorkbook
If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
utoFilter.ApplyFilter Method (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .ApplyFilter
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns True if the worksheet is in the AutoFilter filter mode. Read-only Boolean.
Syntax
expression .FilterMode
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Filters collection that represents all the filters in an autofiltered range. Read-only.
Syntax
expression .Filters
Example
The following example sets a variable to the value of the Criteria1 property of the filter for the first column in the
filtered range on the Crew worksheet.
VBA
With Worksheets("Crew")
If .AutoFilterMode Then
With .AutoFilter.Filters(1)
If .On Then c1 = .Criteria1
End With
End If
End With
AutoFilter.Parent Property (Excel)
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Parent
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Range object that represents the range to which the specified AutoFilter applies.
Syntax
expression .Range
Example
The following example stores in a variable the address for the AutoFilter applied to the Crew worksheet.
VBA
rAddress = Worksheets("Crew").AutoFilter.Range.Address
This example scrolls through the workbook window until the hyperlink range is in the upper-left corner of the
active window.
VBA
Workbooks(1).Activate
Set hr = ActiveSheet.Hyperlinks(1).Range
ActiveWindow.ScrollRow = hr.Row
ActiveWindow.ScrollColumn = hr.Column
AutoFilter.ShowAllData Method (Excel)
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .ShowAllData
See also
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Gets the sort column or columns, and sort order for the AutoFilter collection.
Syntax
expression .Sort
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Remarks
Example
The following example displays the number of axes on embedded chart one on worksheet one.
VBA
With Worksheets(1).ChartObjects(1).Chart
MsgBox.Axes.Count
End With
The following example sets the category axis title text on the chart sheet named "Chart1."
VBA
With Charts("chart1").Axes(xlCategory)
.HasTitle = True
.AxisTitle.Caption = "1994"
End With
Methods
Name
Item
Properties
Name
Application
Count
Creator
Parent
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
Example
This example displays a message about the application that created myObject.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Long value that represents the number of objects in the collection.
Syntax
expression .Count
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
expression A variable that represents an Axes object.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
Parameters
Name Required/Optional Data Type Description
Return Value
Axis
Example
This example sets the title text for the category axis on Chart1.
VBA
With Charts("chart1").Axes.Item(xlCategory)
.HasTitle = True
.AxisTitle.Caption = "1994"
End With
XlAxisType Enumeration (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Specifies the axis type.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Remarks
Use Axes(type, group) where type is the axis type and group is the axis group to return a single Axis object. Type
can be one of the following XlAxisType constants: xlCategory, xlSeries, or xlValue. Group can be one of the
following XlAxisGroup constants: xlPrimary or xlSecondary. For more information, see the Axes method.
Example
The following example sets the category axis title text on the chart sheet named "Chart1."
VBA
With Charts("chart1").Axes(xlCategory)
.HasTitle = True
.AxisTitle.Caption = "1994"
End With
Methods
Name
Delete
Select
Properties
Name
Application
AxisBetweenCategories
AxisGroup
AxisTitle
BaseUnit
BaseUnitIsAuto
Border
CategoryNames
CategoryType
Creator
Crosses
CrossesAt
DisplayUnit
DisplayUnitCustom
DisplayUnitLabel
Format
HasDisplayUnitLabel
HasMajorGridlines
HasMinorGridlines
HasTitle
Height
Left
LogBase
MajorGridlines
MajorTickMark
MajorUnit
MajorUnitIsAuto
MajorUnitScale
MaximumScale
MaximumScaleIsAuto
MinimumScale
MinimumScaleIsAuto
MinorGridlines
MinorTickMark
MinorUnit
MinorUnitIsAuto
MinorUnitScale
Parent
ReversePlotOrder
ScaleType
TickLabelPosition
TickLabels
TickLabelSpacing
TickLabelSpacingIsAuto
TickMarkSpacing
Top
Type
Width
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Remarks
Most bordered objects (all except for the Range and Style objects) have a border thats treated as a single entity,
regardless of how many sides it has. The entire border must be returned as a unit. Use the Border property, such as
from a TrendLine object, to return the Border object for this kind of object.
Example
The following example changes the type and line style of a trend line on the active chart.
VBA
With ActiveChart.SeriesCollection(1).Trendlines(1)
.Type = xlLinear
.Border.LineStyle = xlDash
End With
Range and Style objects have four discrete borders left, right, top, and bottom which can be returned
individually or as a group. Use the Borders property to return the Borders collection, which contains all four
borders and treats the borders as a unit. The following example adds a double border to cell A1 on worksheet one.
VBA
Worksheets(1).Range("A1").Borders.LineStyle = xlDouble
Use Borders(index), where index identifies the border, to return a single Border object. The following example
sets the color of the bottom border of cells A1:G1.
VBA
Worksheets("Sheet1").Range("A1:G1"). _
Borders(xlEdgeBottom).Color = RGB(255, 0, 0)
Index can be one of the following XlBordersIndex constants: xlDiagonalDown, xlDiagonalUp, xlEdgeBottom,
xlEdgeLeft, xlEdgeRight, xlEdgeTop, xlInsideHorizontal, or xlInsideVertical.
Properties
Name
Application
Color
ColorIndex
Creator
LineStyle
Parent
ThemeColor
TintAndShade
Weight
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
Example
This example displays a message about the application that created myObject.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets the primary color of the object, as shown in the table in the remarks section. Use the RGB function
to create a color value. Read/write Variant.
Syntax
expression .Color
Remarks
Object Color
Borders The color of all four borders of a range. If they're not all the same color, Color returns 0 (zero).
Interior The cell shading color or the drawing object fill color.
Example
This example sets the color of the tick-mark labels on the value axis in Chart1.
VBA
Charts("Chart1").Axes(xlValue).TickLabels.Font.Color = _
RGB(0, 255, 0)
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Variant value that represents the color of the border.
Syntax
expression .ColorIndex
Remarks
The color is specified as an index value into the current color palette, or as one of the following XlColorIndex
constants:
xlColorIndexAutomatic
xlColorIndexNone
Example
This example sets the color of the major gridlines for the value axis in Chart1.
VBA
With Charts("Chart1").Axes(xlValue)
If .HasMajorGridlines Then
.MajorGridlines.Border.ColorIndex = 5 'set color to blue
End If
End With
Border.Creator Property (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
Remarks
If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.
Border.LineStyle Property (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets the line style for the border. Read/write XlLineStyle, xlGray25, xlGray50, xlGray75, or
xlAutomatic.
Syntax
expression .LineStyle
Remarks
Example
This example puts a border around the chart area and the plot area of Chart1.
VBA
With Charts("Chart1")
.ChartArea.Border.LineStyle = xlDashDot
With .PlotArea.Border
.LineStyle = xlDashDotDot
.Weight = xlThick
End With
End With
order.Parent Property (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Parent
expression A variable that represents a Border object.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets the theme color in the applied color scheme that is associated with the specified object. Read/write
Variant.
Syntax
expression .ThemeColor
Remarks
Attempting to access a theme color for an object whose color is not currently themed will result in an invalid
request run-time error.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .TintAndShade
Remarks
You can enter a number from -1 (darkest) to 1 (lightest) for the TintAndShade property. Zero (0) is neutral.
Attempting to set this property to a value less than -1 or more than 1 results in a run-time error: "The specified
value is out of range." This property works for both theme colors and nontheme colors.
order.Weight Property (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a XlBorderWeight value that represents the weight of the border.
Syntax
expression .Weight
Example
This example sets the border weight for oval one on Sheet1.
VBA
Worksheets("Sheet1").Ovals(1).Border.Weight = xlMedium
Borders Object (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
A collection of four Border objects that represent the four borders of a Range or Style object.
Remarks
Use the Borders property to return the Borders collection, which contains all four borders.
You can set border properties for an individual border only with Range and Style objects. Other bordered objects,
such as error bars and series lines, have a border thats treated as a single entity, regardless of how many sides it
has. For these objects, you must return and set properties for the entire border as a unit. For more information, see
the Border object.
Example
Worksheets(1).Range("A1").Borders.LineStyle = xlDouble
Use Borders(index), where index identifies the border, to return a single Border object. The following example
sets the color of the bottom border of cells A1:G1 to red.
VBA
Worksheets("Sheet1").Range("A1:G1"). _
Borders(xlEdgeBottom).Color = RGB(255, 0, 0)
Index can be one of the following xlBordersIndex constants: xlDiagonalDown, xlDiagonalUp, xlEdgeBottom,
xlEdgeLeft, xlEdgeRight, or xlEdgeTop, xlInsideHorizontal, or xlInsideVertical.
Properties
Name
Application
Color
ColorIndex
Count
Creator
Item
LineStyle
Parent
ThemeColor
TintAndShade
Value
Weight
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
Example
This example displays a message about the application that created myObject.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets the primary color of the object, as shown in the table in the remarks section. Use the RGB function
to create a color value. Read/write Variant.
Syntax
expression .Color
Remarks
Object Color
Borders The color of all four borders of a range. If they're not all the same color, Color returns 0 (zero).
Interior The cell shading color or the drawing object fill color.
This example sets the color of the tick-mark labels on the value axis in Chart1.
VBA
Charts("Chart1").Axes(xlValue).TickLabels.Font.Color = _
RGB(0, 255, 0)
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Variant value that represents the color of all four borders.
Syntax
expression .ColorIndex
Remarks
This property returns Null if all four borders aren't the same color.
The color is specified as an index value into the current color palette, or as one of the following XlColorIndex
constants:
xlColorIndexAutomatic
xlColorIndexNone
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Long value that represents the number of objects in the collection.
Syntax
expression .Count
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
Remarks
If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Border object that represents one of the borders of either a range of cells or a style.
Syntax
expression .Item(Index)
Remarks
xlDiagonalDown
xlDiagonalUp
xlEdgeBottom
xlEdgeLeft
xlEdgeRight
xlEdgeTop
xlInsideHorizontal
xlInsideVertical
Example
This following example sets the color of the bottom border of cells A1:G1.
VBA
Worksheets("Sheet1").Range("a1:g1"). _
Borders.Item(xlEdgeBottom).Color = RGB(255, 0, 0)
Borders.LineStyle Property (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets the line style for the border. Read/write XlLineStyle, xlGray25, xlGray50, xlGray75, or
xlAutomatic.
Syntax
expression .LineStyle
Example
This example puts a border around the chart area and the plot area of Chart1.
VBA
With Charts("Chart1")
.ChartArea.Border.LineStyle = xlDashDot
With .PlotArea.Border
.LineStyle = xlDashDotDot
.Weight = xlThick
End With
End With
Borders.Parent Property (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Parent
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets the theme color in the applied color scheme that is associated with the specified object. Read/write
Variant.
Syntax
expression .ThemeColor
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .TintAndShade
Remarks
You can enter a number from -1 (darkest) to 1 (lightest) for the TintAndShade property. Zero (0) is neutral.
Attempting to set this property to a value less than -1 or more than 1 results in a run-time error: "The specified
value is out of range." This property works for both theme colors and nontheme colors.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Value
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a XlBorderWeight value that represents the weight of the border.
Syntax
expression .Weight
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
A collection of PivotField objects that represents all the calculated fields in the specified PivotTable report.
Remarks
A report that contains Revenue and Expense fields could have a calculated field named Profit defined as the
amount in the Revenue field minus the amount in the Expense field.
For OLAP data sources, you cannot set this collection, and it always returns Nothing.
Use CalculatedFields(index), where index is specified fields name or index number, to return a single PivotField
object from the CalculatedFields collection.
Example
The following example deletes the calculated fields from the PivotTable report named Pivot1
VBA
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
Parameters
Data
Name Required/Optional Description
Type
Return Value
A PivotField that represents the new calculated field.
Example
This example adds a calculated field to the first PivotTable report on worksheet one.
VBA
Worksheets(1).PivotTables(1).CalculatedFields.Add "PxS", _
"= Product * Sales"
CalculatedFields.Application Property (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
Example
This example displays a message about the application that created myObject.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Long value that represents the number of objects in the collection.
Syntax
expression .Count
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
Remarks
If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
Remarks
If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
expression .Parent
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
A collection of PivotItem objects that represent all the calculated items in the specified PivotTable report.
Remarks
A PivotTable report that contains January, February, and March items could have a calculated item named
FirstQuarter defined as the sum of the amounts in January, February, and March.
Use CalculatedFields(index), where index is the name or index number of the field, to return a single PivotField
object from the CalculatedFields collection.
Example
The following example creates a list of the calculated items in the first PivotTable report on worksheet one, along
with their formulas.
VBA
Set pt = Worksheets(1).PivotTables(1)
For Each ci In pt.PivotFields("Sales").CalculatedItems
r = r + 1
With Worksheets(2)
.Cells(r, 1).Value = ci.Name
.Cells(r, 2).Value = ci.Formula
End With
Next
CalculatedItems.Add Method (Excel)
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
Parameters
Data
Name Required/Optional Description
Type
Return Value
A PivotItem object that represents the new calculated item.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
Example
This example displays a message about the application that created myObject.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Long value that represents the number of objects in the collection.
Syntax
expression .Count
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Item(Index)
Parameters
Name Required/Optional Data Type Description
Index Required Variant The name or index number for the object.
Return Value
A PivotItem object contained by the collection.
Remarks
The text name of the object is the value of the Name and Value properties.
Example
VBA
Worksheets(1).PivotTables(1).PivotFields("year") _
.CalculatedItems.Item(1).Visible = False
CalculatedItems.Parent Property (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Parent
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Represents the calculated fields, calculated items, and named sets for PivotTables with Online Analytical
Processing (OLAP) data sources.
Remarks
Use the Add method or the Item property of the CalculatedMembers collection to return a CalculatedMember
object.
With a CalculatedMember object you can check the validity of a calculated field or item in a PivotTable using the
IsValid property.
Note
The IsValid property will return True if the PivotTable is not currently connected to the data source. Use the
MakeConnection method before testing the IsValid property.
Example
The following example notifies the user if the calculated member is valid or not. This example assumes a
PivotTable exists on the active worksheet that contains either a valid or invalid calculated member.
VBA
Sub CheckValidity()
' Handle run-time error if external source is not an OLEDB data source.
On Error GoTo Not_OLEDB
End Sub
CalculatedMember Object
Application Property
Creator Property
Delete Method
DisplayFolder Property
Dynamic Property
FlattenHierarchies Property
Formula Property
HierarchizeDistinct Property
IsValid Property
MeasureGroup Property
Name Property
NumberFormat Property
Parent Property
ParentHierarchy Property
ParentMember Property
SolveOrder Property
SourceName Property
Type Property
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
This example displays a message about the application that created myObject.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
Remarks
If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Delete
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .DisplayFolder
Return Value
String
Remarks
The value of this property corresponds to the optional value that can be entered in the Display folder text box of
the New/Modify Set dialog box when a named set is created or edited. To create a new named set from data in a
PivotTable based on an OLAP data source, click the PivotTable, click Field, Items, & Sets on the PivotTable Tools
Options tab on the ribbon, click Manage Sets, click New in the Set Manager dialog box, and then click Create Set
using MDX. This will display the New Set dialog box, which contains the Display folder text box. Similarly, if
you select an existing named set in the Set Manager dialog box, and then click Edit, the Modify Set dialog box is
displayed.
This property along with the Dynamic and HierarchizeDistinct properties can only be read for named sets (which
are represented by CalculatedMember objects where the Type property equals xlCalculatedSet). These
properties for cannot be read for calculated members or measures (which are represented by CalculatedMember
objects where the Type property equals xlCalculatedMember). If you attempt to read these properties for
calculated members or measures, a run-time error is raised.
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns whether the specified named set is recalculated with every update. Read-only
Syntax
expression .Dynamic
Return Value
Boolean
Remarks
True if the named set is recalculated with every update; otherwise False.
The value of this property corresponds to the setting of the Recalculate set with every update check box in the
New/Modify Set dialog box that is available when a named set is created or edited. To create a new named set
from data in a PivotTable based on an OLAP data source, click the PivotTable, click Field, Items, & Sets on the
PivotTable Tools Options tab on the ribbon, click Manage Sets, click New in the Set Manager dialog box, and then
click Create Set using MDX. This will display the New Set dialog box, which contains the Recalculate set with
every update check box. Similarly, if you select an existing named set in the Set Manager dialog box, and then
click Edit, the Modify Set dialog box is displayed.
This property along with the DisplayFolder and HierarchizeDistinct properties can only be read for named sets
(which are represented by CalculatedMember objects where the Type property equals xlCalculatedSet). These
properties for cannot be read for calculated members or measures (which are represented by CalculatedMember
objects where the Type property equals xlCalculatedMember). If you attempt to read these properties for
calculated members or measures, a run-time error is raised.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets whether items from all levels of the hierarchy of the specified named set are displayed in the same
field of a PivotTable report based on an OLAP cube. Boolean Read/write
Syntax
expression .FlattenHierarchies
Remarks
True if items from all levels of the hierarchy of the named set are displayed in the same field; otherwise False.
The value of this property corresponds to the setting of the Display items from different levels in separate fields
check box in the New/Modify Set dialog box when a named set is created or edited. To create a new named set
from data in a PivotTable based on an OLAP data source, click the PivotTable, click Field, Items, & Sets on the
PivotTable Tools Options tab on the ribbon, click Manage Sets, click New in the Set Manager dialog box, and then
click Create Set using MDX. This will display the New Set dialog box, which contains the Display items from
different levels in separate fields check box. Similarly, if you select an existing named set in the Set Manager
dialog box, and then click Edit, the Modify Set dialog box is displayed.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a String value that represents the member's formula in multidimensional expressions (MDX) syntax.
Syntax
expression .Formula
Remarks
If the cell contains a constant, this property returns the constant. If the cell is empty, this property returns an empty
string. If the cell contains a formula, the Formula property returns the formula as a string in the same format that
would be displayed in the formula bar (including the equal sign).
If you set the value or formula of a cell to a date, Microsoft Excel checks to see whether that cell is already
formatted with one of the date or time number formats. If not, Microsoft Excel changes the number format to the
default short date number format.
If the range is a one or two-dimensional range, you can set the formula to a Visual Basic array of the same
dimensions. Similarly, you can put the formula into a Visual Basic array.
Setting the formula for a multiple-cell range fills all cells in the range with the formula.
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets whether to order and remove duplicates when displaying the hierarchy of the specified named set
in a PivotTable report based on an OLAP cube. Read/write
Syntax
expression .HierarchizeDistinct
Return Value
Boolean
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Boolean that indicates whether the specified calculated member has been successfully instantiated with
the OLAP provider during the current session.
Syntax
expression .IsValid
Remarks
This property returns True even if the PivotTable is not connected to its data source. Make sure that the PivotTable
is connected before querying the value of the IsValid property.
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .MeasureGroup
Property value
STRING
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Name
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a XlCalcMemNumberFormatType value that represents the number format of the calculated member.
The default value is xlNumberFormatTypeDefault. Read-only.
Syntax
expression .NumberFormat
Property value
XLCALCMEMNUMBERFORMATTYPE
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Parent
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns the name of the current parent hierarchy from the hierarchies that are available on the cube. String Read-
only
Syntax
expression .ParentHierarchy
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns the name of the parent member for the parent hierarchy. String Read-only
Syntax
expression .ParentMember
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Long specifying the value of the calculated member's solve order MDX (Mulitdimensional Expression)
argument. The default value is zero. Read-only.
Syntax
expression .SolveOrder
Example
This example determines the solve order for a calculated member and notifies the user. The example assumes a
PivotTable exists on the active worksheet.
VBA
Sub CheckSolveOrder()
End Sub
CalculatedMember.SourceName Property (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a String value that represents the specified objects name as it appears in the original source data for the
specified PivotTable report.
Syntax
expression .SourceName
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Type
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Remarks
Use the CalculatedMembers property of the PivotTable object to return a CalculatedMembers collection.
There are three supported types of calculated members: Named Sets, Calculated Measures, and Calculated
Members. Object model support has been available for all three of these types since Excel 2010. User interface
support was made available for Named Sets in Excel 2010. In Excel 2013, the OLAP Calculated Members and
Calculated Measures feature was created to build a user interface for the calculated members and measures object
model.
Named Sets are used exactly the same as in Excel 2010. Named Sets should continue to use the method
CalculatedMembers.CalculatedMembers.Add Method (Excel) and the type XlCalculatedMemberType
Enumeration (Excel).
Example
The following example adds a set to a PivotTable, assuming a PivotTable from the FoodMart SQL database exists
on the active worksheet.
VBA
Sub UseCalculatedMember()
Dim pvtTable As PivotTable
Set pvtTable = ActiveSheet.PivotTables(1)
pvtTable.CalculatedMembers.Add Name:="[Beef]", _
Formula:="'{[Product].[All Products].Children}'", _
Type:=xlCalculatedSet
End Sub
Note
For the Add method in the previous example, the Formula argument must have a valid MDX syntax statement.
The Name argument has to be acceptable to the Online Analytical Processing (OLAP) provider and the Type
argument has to be defined.
Add Method
AddCalculatedMember Method
Application Property
Count Property
Creator Property
Item Property
Parent Property
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
Parameters
Data
Name Required/Optional Description
Type
SolveOrder Optional Variant The solve order for the calculated member.
DisplayFolder Optional String The name of the display folder for the calculated member.
Return Value
A CalculatedMember object that represents the new calculated field or calculated item.
Remarks
The Formula argument must contain a valid MDX (Multidimensional Expression) syntax statement. The Name
argument has to be acceptable to the Online Analytical Processing (OLAP) provider and the Type argument has to
be defined.
If you set the Type argument of this method to xlCalculatedSet, then you must call the AddSet method to make
the new field set visible in the PivotTable.
Example
Note
Connection to the cube and existing pivot table is necessary for the sample to run.
VBA
Sub UseAddSet()
strAdd = "[MySet]"
strFormula = "'{[Product].[All Products].[Food].children}'"
End Sub
CalculatedMembers.AddCalculatedMember Method (Excel)
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression
.AddCalculatedMember(Name,Formula,SolveOrder,Type,DisplayFolder,MeasureGroup,ParentHierarchy,ParentM
ember,NumberFormat)
Parameters
Name Required/Optional Data type Description
NumberFormat Optional VARIANT The format of numbers used for calculated members.
Return value
CALCULATEDMEMBER
Remarks
The Formula argument must have a valid MDX (multidimensional expression) syntax statement. The Name
argument has to be acceptable to the Online Analytical Processing (OLAP) provider.
DisplayFolder: Display folders are only valid for calculated measures. They are not valid for calculated
members. The string can have semicolons ; in it. Semicolons designate multiple display folders. For
example, if you use the string my folder1;myfolder2 then the calculated measure will show in two display
folders one named myfolder1 the other named ?myfolder2?. The string can have backslashes \. This
designates a hierarchical path for the display folder. For example, if you use the string welcome\to\seattle
there will be a display folder called welcome that contains a display folder called to which contains a
display folder called seattle. Display folders are virtual folders.? They do not really exist in the same sense
that we think of system folders. They only exist for purposes of displaying the calculated measures.
NumberFormat: The number formats can only be set by macros. There is no user interface for setting
them. This is the only property that cannot be set via the user interface. The type is always
xlNumberFormatTypeDefault when a calculated member is created via the user interface. The number
formats are only valid for calculated members. They are not valid for calculated measures.
ParentHierarchy: The parent hierarchy can be any valid MDX hierarchy. Parent hierarchies are only valid
for calculated members. They are not valid for calculated measures. If a parent member is chosen that is in
a different parent hierarchy, the parent hierarchy will be automatically changed to match the parent
hierarchy of the parent member. For example, assume the following macro for a calculated member:
T-SQL
OLEDBConnection.CalculatedMembers.AddCalculatedMember Name:="[UK+US]", _
Formula:= _
"[Customer].[Customer Geography].[Country].&[United Kingdom] + [Customer].
[Customer Geography].[Country].&[United States] " _
, Type:=xlCalculatedMember, SolveOrder:=0, ParentHierarchy:= _
"[Account].[Accounts]", ParentMember:= _
"[Customer].[Customer Geography].[Australia]", NumberFormat:= _
xlNumberFormatTypePercent
In this case you have specified that the parent member is from the [Customer].[Customer Geography]
hierarchy yet you have given the parent hierarchy as [Account].[Accounts]. When the member is created, it
will use the parent hierarchy of the parent member which is [Customer].[Customer Geography] and when
you look in the Manage Calculations dialog in the UI, it will show [Customer].[Customer Geography] as
the parent hierarchy rather than the one specified in the macro, i.e. [Account].[Accounts].
Example
The following code sample adds a calculated measure to a PivotTable.
Note
In both of these samples, the PivotTable must be refreshed after creating the calculation in order to view it in the
user interface.
VBA
Sub AddCalculatedMeasure()
End Sub
The following code sample adds a calculated member to a PivotTable.
VBA
Sub AddCalculatedMember()
End Sub
CalculatedMembers.Application Property (Excel)
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
Example
This example displays a message about the application that created myObject.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Long value that represents the number of objects in the collection.
Syntax
expression .Count
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
Remarks
If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XC
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Item(Index)
Parameters
Name Required/Optional Data Type Description
Example
The following example notifies the user if the calculated member is valid or not. This example assumes a
PivotTable exists on the active worksheet that contains either a valid or invalid calculated member.
VBA
Sub CheckValidity()
' Handle run-time error if external source is not an OLEDB data source.
On Error GoTo Not_OLEDB
Not_OLEDB:
MsgBox "The source is not an OLEDB data source."
Exit Sub
End Sub
CalculatedMembers.Parent Property (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Parent
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Remarks
Example
The following example specifies the following attributes of shape three (a line callout) on myDocument: the
callout will have a vertical accent bar that separates the text from the callout line; the angle between the callout
line and the side of the callout text box will be 30 degrees; there will be no border around the callout text; the
callout line will be attached to the top of the callout text box; and the callout line will contain two segments. For
this example to work, shape three must be a callout.
VBA
Concepts
Excel Object Model Reference
Other resources
CalloutFormat Object Members
Accent Property
Angle Property
Application Property
AutoAttach Property
AutoLength Property
AutomaticLength Method
Border Property
Creator Property
CustomDrop Method
CustomLength Method
Drop Property
DropType Property
Gap Property
Length Property
Parent Property
PresetDrop Method
Type Property
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Allows the user to place a vertical accent bar to separate the callout text from the callout line. Read/write
MsoTriState.
Syntax
expression .Accent
Remarks
msoCTrue
msoFalse
msoTriStateMixed
msoTriStateToggle
msoTrue. A vertical accent bar separates the callout text from the callout line.
Example
This example adds to myDocument an oval and a callout that points to the oval. The callout text wont have a
border, but it will have a vertical accent bar that separates the text from the callout line.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets the angle of the callout line. If the callout line contains more than one line segment, this property
returns or sets the angle of the segment that is farthest from the callout text box. Read/write
MsoCalloutAngleType.
Syntax
expression .Angle
Remarks
If you set the value of this property to anything other than msoCalloutAngleAutomatic, the callout line maintains
a fixed angle as you drag the callout.
Example
This example sets to 90 degrees the callout angle for a callout named "callout1" on myDocument.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
Example
This example displays a message about the application that created myObject.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
True if the place where the callout line attaches to the callout text box changes depending on whether the origin of
the callout line (where the callout points to) is to the left or right of the callout text box. Read/write MsoTriState.
Syntax
expression .AutoAttach
Remarks
msoCTrue
msoFalse
msoTriStateMixed
msoTriStateToggle
msoTrue. The place where the callout line attaches to the callout text box changes depending on whether the
origin of the callout line (where the callout points to) is to the left or right of the callout text box.
When the value of this property is True, the drop value (the vertical distance from the edge of the callout text box
to the place where the callout line attaches) is measured from the top of the text box when the text box is to the
right of the origin, and its measured from the bottom of the text box when the text box is to the left of the origin.
When the value of this property is False, the drop value is always measured from the top of the text box,
regardless of the relative positions of the text box and the origin. Use the CustomDrop method to set the drop
value, and use the Drop property to return the drop value.
Setting this property affects a callout only if it has an explicitly set drop value that is, if the value of the
DropType property is msoCalloutDropCustom. By default, callouts have explicitly set drop values when theyre
created.
Example
This example adds two callouts to myDocument. If you drag the text box for each of these callouts to the left of
the callout line origin, the place on the text box where the callout line attaches will change for the automatically
attached callout.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Applies only to callouts whose lines consist of more than one segment (types msoCalloutThree and
msoCalloutFour). Read/write MsoTriState.
Syntax
expression .AutoLength
Remarks
msoCTrue
msoFalse. The first segment of the callout retains the fixed length specified by the Length property whenever the
callout is moved.
msoTriStateMixed
msoTriStateToggle
msoTrue. The first segment of the callout line (the segment attached to the text callout box) is scaled
automatically whenever the callout is moved.
This property is read-only. Use the AutomaticLength method to set this property to msoTrue, and use the
CustomLength method to set this property to mosFalse.
Example
This example toggles between an automatically scaling first segment and one with a fixed length for the callout
line for shape one on myDocument. For the example to work, shape one must be a callout.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Specifies that the first segment of the callout line (the segment attached to the text callout box) be scaled
automatically when the callout is moved. Use the CustomLength method to specify that the first segment of the
callout line retain the fixed length returned by the Length property whenever the callout is moved. Applies only to
callouts whose lines consist of more than one segment (types msoCalloutThree and msoCalloutFour).
Syntax
expression .AutomaticLength
Remarks
Example
This example toggles between an automatically scaling first segment and one with a fixed length for the callout
line for shape one on myDocument. For the example to work, shape one must be a callout.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a MsoTriState value that represents the visibility options for the border of the object.
Syntax
expression .Border
Remarks
The value of this property can be set to one of the following MsoTriState constants:
msoTriStateToggle Allows the user to switch the border from visible to invisible and vice versa.
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Sets the vertical distance (in points) from the edge of the text bounding box to the place where the callout line
attaches to the text box. This distance is measured from the top of the text box unless the AutoAttach property is
set to True and the text box is to the left of the origin of the callout line (the place that the callout points to), in
which case the drop distance is measured from the bottom of the text box.
Syntax
expression .CustomDrop(Drop)
Parameters
Name Required/Optional Data Type Description
Example
This example sets the custom drop distance to 14 points, and specifies that the drop distance always be measured
from the top. For the example to work, shape three must be a callout.
VBA
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Specifies that the first segment of the callout line (the segment attached to the text callout box) retain a fixed
length whenever the callout is moved. Use the AutomaticLength method to specify that the first segment of the
callout line be scaled automatically whenever the callout is moved. Applies only to callouts whose lines consist of
more than one segment (types msoCalloutThree and msoCalloutFour).
Syntax
expression .CustomLength(Length)
Parameters
Name Required/Optional Data Type Description
Length Required Single The length of the first segment of the callout, in points.
Remarks
Applying this method sets the AutoLength property to False and sets the Length property to the value specified
for the Length argument.
Example
This example toggles between an automatically scaling first segment and one with a fixed length for the callout
line for shape one on myDocument. For the example to work, shape one must be a callout.
VBA
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
For callouts with an explicitly set drop value, this property returns the vertical distance (in points) from the edge of
the text bounding box to the place where the callout line attaches to the text box. Read-only Single.
Syntax
expression .Drop
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a value that indicates where the callout line attaches to the callout text box. Read-only
MsoCalloutDropType.
Syntax
expression .DropType
Remarks
msoCalloutDropCenter
msoCalloutDropMixed
msoCalloutDropBottom
msoCalloutDropCustom
msoCalloutDropTop
If the callout drop type is msoCalloutDropCustom, the values of the Drop and AutoAttach properties and the
relative positions of the callout text box and callout line origin (the place that the callout points to) are used to
determine where the callout line attaches to the text box.
This property is read-only. Use the PresetDrop method to set the value of this property.
Example
This example replaces the custom drop for shape one on myDocument with one of two preset drops, depending on
whether the custom drop value is greater than or less than half the height of the callout text box. For the example
to work, shape one must be a callout.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets the horizontal distance (in points) between the end of the callout line and the text bounding box.
Read/write Single.
Syntax
expression .Gap
Example
This example sets the distance between the callout line and the text bounding box to 3 points for shape one on
myDocument. For the example to work, shape one must be a callout.
VBA
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Single value that represents the length (in points) of the first segment of the callout line (the segment
attached to the text callout box.)
Syntax
expression .Length
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Parent
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Specifies whether the callout line attaches to the top, bottom, or center of the callout text box or whether it attaches
at a point that?s a specified distance from the top or bottom of the text box.
Syntax
expression .PresetDrop(DropType)
Example
This example specifies that the callout line attach to the top of the text bounding box for shape one on
myDocument. For the example to work, shape one must be a callout.
VBA
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a MsoCalloutType value that represents the callout format type.
Syntax
expression .Type
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns an Application object that represents the Microsoft Excel application. Read-only.
Syntax
expression .Application
Example
This example displays a message about the application that created myObject.
VBA
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Long value that represents the number of objects in the CategoryCollection (returns the number of
categories visible in the chart). Read-only.
Syntax
expression .Count
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which the specified object was created. Read-only Long.
Syntax
expression .Creator
expression A variable that represents a CategoryCollection Object (Excel) object.
Remarks
Because the object was created in Microsoft Excel, this property returns the hexadecimal value, 5843454C, which
represents the string "XCEL".
Property value
XLCREATOR
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which the specified object was created. Read-only Long.
Syntax
expression .Creator
Remarks
Because the object was created in Microsoft Excel, this property returns the hexadecimal value, 5843454C, which
represents the string "XCEL".
Property value
XLCREATOR
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns an Object that represents the parent object of the specified CategoryCollection Object (Excel) object.
Read-only.
Syntax
expression .Parent
Remarks
This property will return the Chart object that owns this collection of categories.
Property value
OBJECT
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Remarks
Use the FindFormat or ReplaceFormat properties of the Application object to return a CellFormat object.
With a CellFormat object, you can use the Borders , Font , or Interior properties of the CellFormat object, to
define the search criteria for the cell format.
Example
The following example sets the search criteria for the interior of the cell format.
VBA
Sub ChangeCellFormat()
' Find and replace cell A1's yellow interior with green.
ActiveCell.Replace What:="", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=True, _
ReplaceFormat:=True
MsgBox "The cell format for cell A1 is replaced with a green interior."
End Sub
Methods
Name
Clear
Properties
Name
AddIndent
Application
Borders
Creator
Font
FormulaHidden
HorizontalAlignment
IndentLevel
Interior
Locked
MergeCells
NumberFormat
NumberFormatLocal
Orientation
Parent
ShrinkToFit
VerticalAlignment
WrapText
See also
Concepts
Excel Object Model Reference
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Variant value that indicates if text is automatically indented when the text alignment in a cell is
set to equal distribution (either horizontally or vertically.)
Syntax
expression .AddIndent
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
Example
This example displays a message about the application that created myObject.
VBA
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Borders collection that represents the search criteria based on the cell's border format.
Syntax
expression .Borders
Example
This example sets the search criteria to identify the borders of cells that have a continuous and thick style bottom-
edge, creates a cell with this condition, finds this cell, and notifies the user.
Note
The default color of the border is used in this example, therefore the color index is not changed.
VBA
Sub SearchCellFormat()
' Set the search criteria for the border of the cell format.
With Application.FindFormat.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
End With
End Sub
CellFormat.Clear Method (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
expression .Clear
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Font object, allowing the user to set or return the search criteria based on the cell's font format.
Syntax
expression .Font
Example
This example sets the search criteria to identify cells that contain red font, creates a cell with this condition, finds
this cell, and notifies the user.
VBA
Sub SearchCellFormat()
' Set the search criteria for the font of the cell format.
Application.FindFormat.Font.ColorIndex = 3
' Set the color index of the font for cell A5 to red.
Range("A5").Font.ColorIndex = 3
Range("A5").Formula = "Red font"
Range("A1").Select
MsgBox "Cell A5 has red font"
MsgBox "Microsoft Excel has found this cell matching the search criteria."
End Sub
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Variant value that indicates if the formula will be hidden when the worksheet is protected.
Syntax
expression .FormulaHidden
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Variant value that represents the horizontal alignment for the specified object.
Syntax
expression .HorizontalAlignment
The value of this property can be set to one of the following constants:
xlCenter
xlDistributed
xlJustify
xlLeft
xlRight
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Variant value that represents the indent level for the cell or range. Can be an integer from 0 to
15.
Syntax
expression .IndentLevel
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns an Interior object allowing the user to set or return the search criteria based on the cell's interior format.
Syntax
expression .Interior
This example sets the search criteria to identify cells that contain a solid yellow interior, creates a cell with this
condition, finds this cell, and notifies the user.
VBA
Sub SearchCellFormat()
' Set the search criteria for the interior of the cell format.
With Application.FindFormat.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End Sub
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Locked
Remarks
This property returns True if the object is locked, False if the object can be modified when the sheet is protected,
or Null if the specified range contains both locked and unlocked cells.
Example
This example unlocks cells A1:G37 on Sheet1 so that they can be modified when the sheet is protected.
VBA
Worksheets("Sheet1").Range("A1:G37").Locked = False
Worksheets("Sheet1").Protect
CellFormat.MergeCells Property (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .MergeCells
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Variant value that represents the format code for the object.
Syntax
expression .NumberFormat
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Variant value that represents the format code for the object as a string in the language of the user.
Syntax
expression .NumberFormatLocal
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Orientation
Remarks
The value of this property can be set to an integer value from 90 to 90 degrees or to one of the following
constants:
xlDownward
xlHorizontal
xlUpward
xlVertical
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Parent
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Variant value that indicates if text automatically shrinks to fit in the available column width.
Syntax
expression .ShrinkToFit
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Variant value that represents the vertical alignment of the specified object.
Syntax
expression .VerticalAlignment
Remarks
The value of this property can be set to one of the following constants:
xlBottom
xlCenter
xlDistributed
xlJustify
xlTop
Example
This example sets the height of row 2 on Sheet1 to twice the standard height and then centers the contents of the
row vertically.
VBA
Worksheets("Sheet1").Rows(2).RowHeight = _
2 * Worksheets("Sheet1").StandardHeight
Worksheets("Sheet1").Rows(2).VerticalAlignment = xlVAlignCenter
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Variant value that indicates if Microsoft Excel wraps the text in the object.
Syntax
expression .WrapText
Remarks
This property returns True if text is wrapped in all cells within the specified range, False if text is not wrapped in
all cells within the specified range, or Null if the specified range contains some cells that wrap text and other cells
that don't.
Other Versions
Contribute to this content
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Remarks
The Characters object lets you modify any sequence of characters contained in the full text string.
Use Characters(start, length), where start is the start character number and length is the number of characters, to
return a Characters object.
Example
The following example adds text to cell B1 and then makes the second word bold.
VBA
With Worksheets("Sheet1").Range("B1")
.Value = "New Title"
.Characters(5, 5).Font.Bold = True
End With
The Characters method is necessary only when you need to change some of an objects text without affecting the
rest (you cannot use the Characters method to format a portion of the text if the object doesnt support rich text).
To change all the text at the same time, you can usually apply the appropriate method or property directly to the
object. The following example formats the contents of cell A5 as italic.
VBA
Worksheets("Sheet1").Range("A5").Font.Italic = True
Methods
Name
Delete
Insert
Properties
Name
Application
Caption
Count
Creator
Font
Parent
PhoneticCharacters
Text
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax
expression .Application
Example
This example displays a message about the application that created myObject.
VBA
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a String value that represents the text of this range of characters.
Syntax
expression .Caption
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Long value that represents the number of objects in the collection.
Syntax
expression .Count
Example
VBA
Sub MakeSuperscript()
Dim n As Integer
n = Worksheets("Sheet1").Range("A1").Characters.Count
Worksheets("Sheet1").Range("A1").Characters(n, 1) _
.Font.Superscript = True
End Sub
Characters.Creator Property (Excel)
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax
expression .Creator
expression A variable that represents a Characters object.
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Syntax
expression .Delete
Other Versions
Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a Font object that represents the font of the specified object.
Syntax
expression .Font
Syntax
expression .Insert(String)
Other Versions
Syntax
expression .Parent
Other Versions
Returns or sets the text for the specified object. Read/write String.
Syntax
expression .Text