This documentation is archived and is not being maintained.

WorksheetBase.Scripts Property

Gets the Microsoft.Office.Core.Scripts collection, which contains Script objects representing blocks of script or code in the worksheet when it is saved as a Web page.

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

public Scripts Scripts { get; }

Property Value

Type: Microsoft.Office.Core.Scripts
The Microsoft.Office.Core.Scripts collection, which contains Script objects representing blocks of script or code in the worksheet when it is saved as a Web page.

The following code example uses the Scripts property to display the number of scripts in the current worksheet, add a script to the worksheet, and then display the updated number of scripts.

This example is for a document-level customization.

private void AddScript()
{
    MessageBox.Show("There are " + this.Scripts.Count +
        " scripts in this worksheet.");

    this.Scripts.Add(this.Range["A1"],
        Office.MsoScriptLocation.msoScriptLocationInBody,
        Office.MsoScriptLanguage.msoScriptLanguageVisualBasic,
        "ScriptOne", String.Empty, @"MsgBox ""This is ScriptOne.""");

    MessageBox.Show("There are " + this.Scripts.Count +
        " scripts in this worksheet.");
}

Show: