Hide blank sheets that do not have an object embedded

Bagsy

Active Member
Joined
Feb 26, 2005
Messages
467
Office Version
  1. 365
Platform
  1. Windows
I wonder if anybody can tell me if this is possible
I have a workbook with a few blank sheets; these are used to embed pdf documents if required. However I would like to is run some code to hide the empty sheets if there has not been a pdf document embedded within that sheet.
Below code will hide empty sheets but also hide those with an embedded document which I need to avoid.
Any help is much appreciated
Code:
Sub HideBlank()

Dim ws As Worksheet

    For Each ws In ThisWorkbook.Worksheets
        If (ws.name <> "PSW") And (ws.name <> "Del COC") And (ws.name <> "Del COC") And (ws.name <> "Del Note") And (ws.name <> "COC") And (ws.name <> "L1 Insp Report (1)") And _
        (ws.name <> "L1 Insp Report (2)") And (ws.name <> "L1 Insp Report (3)") And (ws.name <> "L1 Insp Report (4)") And (ws.name <> "L1 Insp Report (5)") And (ws.name <> "L1 Insp Report (6)") Then
            If WorksheetFunction.CountA(ws.Cells) = 0 Then
                ws.Visible = xlSheetHidden
            End If
        End If
    Next
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try...

Code:
Sub HideBlank()

Dim ws As Worksheet


    For Each ws In ThisWorkbook.Worksheets
        If (ws.Name <> "PSW") And (ws.Name <> "Del COC") And (ws.Name <> "Del COC") And (ws.Name <> "Del Note") And (ws.Name <> "COC") And (ws.Name <> "L1 Insp Report (1)") And _
        (ws.Name <> "L1 Insp Report (2)") And (ws.Name <> "L1 Insp Report (3)") And (ws.Name <> "L1 Insp Report (4)") And (ws.Name <> "L1 Insp Report (5)") And (ws.Name <> "L1 Insp Report (6)") Then
            If WorksheetFunction.CountA(ws.Cells) = 0 Then
                If ws.Shapes.Count = 0 Then
                    ws.Visible = xlSheetHidden
                End If
            End If
        End If
    Next
End Sub

Note that the macro won't hide sheets that contain...

Code:
1) shapes, such as rectangles, circles, etc.

2) activeX objects, such as commnad buttons, labels, etc.

3) other types of embedded files, such as an Excel workbook, Word workbook, etc.

If you only want to hide sheets when there are no embedded PDF files, the macro will need to be amended. Post back if this is the case.
 
Upvote 0
That is brillaint,Domenic. Thank you so much
Gary
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top