Worksheet.Scenarios Method (2007 System)

Gets an object that represents either a single scenario (a Scenario object) or a collection of scenarios (a Scenarios object) on the worksheet.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
Public Function Scenarios ( _
    Index As Object _
) As Object
'Usage
Dim instance As Worksheet 
Dim Index As Object 
Dim returnValue As Object 

returnValue = instance.Scenarios(Index)
public Object Scenarios(
    Object Index
)
public:
Object^ Scenarios(
    Object^ Index
)
public function Scenarios(
    Index : Object
) : Object

Parameters

  • Index
    Type: System.Object

    The name or number of the scenario. Use an array to specify more than one scenario.

Return Value

Type: System.Object
An object that represents either a single scenario (a Scenario object) or a collection of scenarios (a Scenarios object) on the worksheet.

Examples

The following code example uses the Scenarios method to add a new scenario to the current worksheet, and then displays the Scenario Manager dialog to verify that the scenario was added.

This example is for a document-level customization.

Private Sub CreateScenario()
    Dim range1 As Excel.Range = Me.Range("A1", "B10")
    range1.Formula = "=rand()" 

    Dim scenarios1 As Excel.Scenarios = _
        CType(Me.Scenarios(), Excel.Scenarios)

    Dim newScenario As Excel.Scenario = _
        scenarios1.Add("New Scenario", range1)

    ' Show Scenario Manager dialog to verify that the scenario was added. 
    Me.Application.Dialogs(Excel.XlBuiltInDialog.xlDialogScenarioCells).Show()
End Sub
private void CreateScenario()
{   
    Excel.Range range1 = this.Range["A1", "B10"];
    range1.Formula = "=rand()";

    Excel.Scenarios scenarios1 =
        (Excel.Scenarios)this.Scenarios(missing);

    Excel.Scenario newScenario = scenarios1.Add("New Scenario", 
        range1, missing, missing, missing, missing);

    // Show Scenario Manager dialog to verify that the scenario was added. 
    this.Application.Dialogs[Excel.XlBuiltInDialog.xlDialogScenarioCells].Show(
        missing, missing, missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing);
}

.NET Framework Security

See Also

Reference

Worksheet Class

Worksheet Members

Microsoft.Office.Tools.Excel Namespace