Add Method (Scripts Collection) Example

This example adds a new Script to the specified range on worksheet one in the active workbook.

Dim rngScriptAnchorRange As Range
Dim objNewScript As Script

Set rngScriptAnchorRange = ActiveWorkbook. _
    Worksheets(1).Range("B5")
Set objNewScript = ActiveWorkbook. _
    Worksheets(1).Scripts.Add(rngScriptAnchorRange, _
      msoScriptLocationInBody, _
      msoScriptLanguageVisualBasic, _
      "MyNewScript", , _
      "MsgBox (""Added Script object MyNewScript"")")