VBA - DeleteAllSheetsButOneNamedMacro

VBA - DeleteAllSheetsButOneNamedMacro

(click here to get the code) Unchanging conditions are essential for successful data processing. The best way is to use only one control sheet with buttons and create all other sheets from scratch. When starting the file this SW deletes all sheets except for the sheet named "Macro". New sheets are then created using other parts of the program. (this programm is free to use, tested, works properly)

Private Sub Workbook_Open()
    DeleteAllWsButWsMacroVer001.DeleteAllButMacro
End Sub

Sub DeleteAllButMacro()
    Dim ws As Worksheet
    Dim blnWsMacroExists As Boolean

    blnWsMacroExists = False
    
    'check if worksheet "Macro" exists
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name = "Macro" Then
            blnWsMacroExists = True
            Exit For
        End If
    Next ws
    
    'if worksheet "Macro" exists, then delete all others
    If blnWsMacroExists Then
        Application.DisplayAlerts = False 'disable warning messages
        
        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> "Macro" Then
                ws.Delete
            End If
        Next ws
        
        Application.DisplayAlerts = True 'enable warning messages
    Else
        MsgBox "Worksheet 'Macro' not found. & vbcrlf" _
            & "No sheets were deleted.", vbExclamation
    End If
End Sub        

要查看或添加评论,请登录

Gabriel Kovacs的更多文章

  • VBA-fnDateIsGenuineV001

    VBA-fnDateIsGenuineV001

    (this code is free to use, tested, works properly) - click here to get the code

  • VBA-fnRegexDataItemIsValidV001

    VBA-fnRegexDataItemIsValidV001

    (this code is free to use, tested, works properly) - click here to get the code

  • VBA-AddressA1toR1C1conversionV001

    VBA-AddressA1toR1C1conversionV001

    (this code is free to use, tested, works properly) - click here to get the code

    14 条评论
  • VBA-fnDataTypeDetectionV001

    VBA-fnDataTypeDetectionV001

    (this code is free to use, tested, works properly) - click here to get the code

    4 条评论
  • VBA-fnDirectoryPathFormatCheckV001

    VBA-fnDirectoryPathFormatCheckV001

    (this code is free to use, tested, works properly) - click here to get the code

    4 条评论
  • VBA-fnFileExtensionValidityCheckV01

    VBA-fnFileExtensionValidityCheckV01

    (this code is free to use, tested, works properly)

    2 条评论
  • VBA-DeleteAllSheetsExceptInArrayV02

    VBA-DeleteAllSheetsExceptInArrayV02

    (this code is free to use, tested, works properly)

    4 条评论
  • VBA-DeleteAllSheetsExceptInArrayV01

    VBA-DeleteAllSheetsExceptInArrayV01

    (this code is free to use, tested, works properly)

    9 条评论
  • VBA-fnSheetExistenceDetectionV002

    VBA-fnSheetExistenceDetectionV002

    (this code is free to use, tested, works properly)

    5 条评论
  • VBA-fnSpacesCountInSpaceOnlyStrV001

    VBA-fnSpacesCountInSpaceOnlyStrV001

    (this code is free to use, tested, works properly - click here to get the code)

    8 条评论

社区洞察

其他会员也浏览了