home

-- Excel Add Worksheet
Author Nigel Rivett

This vbscript adds a worksheet to an excel workbook with a particular name.
If the worksheet already exists then it is deleted first.

    Dim wb As Excel.Workbook
    Set wb = Excel.ActiveWorkbook
    Dim ws As Excel.Worksheet

    ' delete the previous script worksheet
    For Each ws In wb.Worksheets
        If ws.Name = "MetadataScript" Then
            Application.DisplayAlerts = False
            ws.Delete
            Application.DisplayAlerts = False
        End If
    Next

    ' Add a blank worksheet to the end of the workbook named MetadataScript.
    Set gwsMetadataScript = wb.Worksheets.Add(, wb.Worksheets(wb.Worksheets.Count))
    gwsMetadataScript.Name = "MetadataScript"


home