+ Reply to Thread
Results 1 to 2 of 2

Daniello1 - How to write a macro that would delete a sheet across multiple workbooks

Hybrid View

tigeravatar Daniello1 - How to write a... 08-15-2012, 11:09 AM
Daniello1 Re: Daniello1 - How to write... 08-15-2012, 05:31 PM
  1. #1
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Daniello1 - How to write a macro that would delete a sheet across multiple workbooks

    I am creating this thread on behalf of new user Daniello1. He replied to an older thread located here: http://www.excelforum.com/excel-prog...html?p=2895634

    That thread was for deleting all but one sheet in several workbooks. Daniello1's post in that thread:
    Quote Originally Posted by Daniello1 View Post
    Hi Tigeravatar
    I have the opposite problem - how to write a macro that would delete certain spreadsheet across multiple workbooks (this spreadheet has the same name on almost 1000 identical workbooks I have). Can you please advice?
    Daniel

    So he is asking how to delete a single specific sheet in multiple workbooks. Daniello1, give this try:
    Sub WorksheetDeletionMacro_for_Daniello1()
        
        Const strSheetName As String = "Sheet1"
        
        Dim ws As Worksheet
        Dim strFldrPath As String
        Dim strFileName As String
        Dim strSep As String
        
        
        With Application.FileDialog(msoFileDialogFolderPicker)
            .AllowMultiSelect = False
            If .Show = False Then Exit Sub  'Pressed cancel
            strFldrPath = .SelectedItems(1)
        End With
        
        strSep = Application.PathSeparator
        strFileName = Dir(strFldrPath & strSep & "*.xls*")
        
        With Application
            .DisplayAlerts = False
            .ScreenUpdating = False
        End With
        
        Do While Len(strFileName) > 0
            With Workbooks.Open(strFldrPath & strSep & strFileName)
                If .Sheets.Count > 1 Then
                    For Each ws In .Sheets
                        If LCase(ws.Name) = LCase(strSheetName) Then
                            ws.Delete
                            .Save
                            Exit For
                        End If
                    Next ws
                End If
                .Close False
            End With
            strFileName = Dir
        Loop
        
        With Application
            .DisplayAlerts = True
            .ScreenUpdating = True
        End With
        
        Set ws = Nothing
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  2. #2
    Registered User
    Join Date
    07-21-2012
    Location
    Prague, Czech
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Daniello1 - How to write a macro that would delete a sheet across multiple workbooks

    Hi again tigeravatar
    Thanks a lot! Just tested and works great, much appreciated.
    Daniello1

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1