Expression Property

Microsoft Office Web Components Visual Basic

expression.Expression

expression    Required. An expression that returns a one of the objects in the Applies To list.

Remarks

The Expression property will return a blank string if it is not used with a calculated field or calculated total.

Example

The following example displays the current expression used for a calculated field named "Variance" in PivotTable1. When you edit the expression and then click OK, the new expression is assigned to the Variance field.

Sub Change_Expression()

    Dim vwView
    Dim cfCalcField
    Dim strCurrentExpression
    Dim strNewExpression

    Set vwView = PivotTable1.ActiveView

    ' Set a varible to the calculated field.
    Set cfCalcField = _
        vwView.Fieldsets("Variance").Fields("Variance")

    ' Set a variable to the current expression used in the
    ' Variance field.
    strCurrentExpression = cfCalcField.Expression

    ' Display an input box that contains the current expression for the
    ' Variance field. Edit the expression and then click OK.
    strNewExpression = InputBox("Edit the expression used for the calculated" & _
        "field and then click OK.", , strCurrentExpression)

    ' Set the expression used to calculate the Variance field to the
    ' expression entered in the input box.
    cfCalcField.Expression  = strNewExpression

End Sub