Trying adding a sheet to the code

Bomba
3StarLounger
Posts: 281
Joined: 20 Jan 2019, 19:43

Trying adding a sheet to the code

Post by Bomba »

I am trying to add another worksheet "Rep 36" to the code below so that pictures remain there. An error is appearing saying:
Compile error
Syntax error
This is the original code:

Code: Select all

Sub DeleteAllObjectsInFolder()
    Const strFolder = "C:\...\Library\"
    Dim strFile As String
    Dim wbk As Workbook
    Dim wsh As Worksheet
    Dim i As Long
    Dim f As Boolean
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Calculation = xlCalculationManual
    strFile = Dir(strFolder & "*.xls*")
    Do While strFile <> ""
        Set wbk = Workbooks.Open(Filename:=strFolder & strFile, UpdateLinks:=False)
        For Each wsh In wbk.Worksheets
          If UCase(wsh.Name) <> "DASH" Then
                f = wsh.ProtectContents
                If f Then
                    wsh.Unprotect
                End If
                For i = wsh.Shapes.Count To 1 Step -1
                    wsh.Shapes(i).Delete
                Next i
                If f Then
                    wsh.Protect
                End If
            End If
        Next wsh
        wbk.Close SaveChanges:=True
        strFile = Dir
    Loop
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
I am adding "Rep 36" to this line.

Code: Select all

If UCase(wsh.Name) <> "DASH", "Rep 36" Then
Thanks

User avatar
HansV
Administrator
Posts: 78494
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Trying adding a sheet to the code

Post by HansV »

Change

Code: Select all

            If UCase(wsh.Name) <> "DASH" Then
                f = wsh.ProtectContents
                If f Then
                    wsh.Unprotect
                End If
                For i = wsh.Shapes.Count To 1 Step -1
                    wsh.Shapes(i).Delete
                Next i
                If f Then
                    wsh.Protect
                End If
            End If
to

Code: Select all

            Select Case UCase(wsh.Name)
              Case "DASH", "REP 36" ' note the upper case!
                ' Skip these
              Case Else
                f = wsh.ProtectContents
                If f Then
                    wsh.Unprotect
                End If
                For i = wsh.Shapes.Count To 1 Step -1
                    wsh.Shapes(i).Delete
                Next i
                If f Then
                    wsh.Protect
                End If
            End Select
Best wishes,
Hans

Bomba
3StarLounger
Posts: 281
Joined: 20 Jan 2019, 19:43

Re: Trying adding a sheet to the code

Post by Bomba »

Thanks a lot Master.