Excel – VBA to add new sheet in a closed excel without opening & get the sheet name added

excelvba

I have an excel "Closed.Xls" which is not opened currently.

Please let me know how to add new sheets in to this closed excel file. I know how to add new sheets in current excel.

Dim WS as Worksheet
Set WS = Sheets.Add

Please let me know how to

  1. add new sheets in a closed excel using VBA, and
  2. get the name of the sheet added

Note: I don't want to rename the sheet.

Thanks

Best Answer

Something like this will will do what you want. It is not possible without opening the workbook but if you turn off screen updating it gives the appearance of not being opened.

Option Explicit
Sub Add_Sheet_ClosedBook()
    Dim bk As Workbook
    Dim sh As Worksheet
    Dim shName As String

    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
    Set bk = .Workbooks.Open _
    ("Path to Book.xls")
    End With

    With bk
        Set sh = .Sheets.Add
        shName = sh.Name
        .Save
        .Close
    End With

    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
    End With
End Sub
Related Topic