如何使msgbox在最后显示工作表数量?

时间:2019-01-10 22:17:35

标签: excel vba

excel vba项目需要此文件。基本上,我已经使用宏创建了许多工作表,并且在执行结束时,宏应该告诉创建了多少个工作表。

1 个答案:

答案 0 :(得分:0)

类似...

Option Explicit

Public Sub CountAddedSheets()

    Dim vInitialCount As Long
    Dim vWorkbook As Workbook

    Set vWorkbook = ActiveWorkbook

    ' Remember the initial number of sheets
    vInitialCount = ActiveWorkbook.Worksheets.Count

    ' Your code to add worksheets ... for example ...
    vWorkbook.Worksheets.Add

    ' Show the number of worksheets added
    MsgBox "Number of worksheets added: " & (vWorkbook.Worksheets.Count - vInitialCount)

End Sub