Protect Workbook Struture and Printing Hidden Worksheet

Jenny_MO

New Member
Joined
May 24, 2018
Messages
4
I'm having some trouble with the command button code below when I protect my workbook. I can protect the worksheet the button is on and lock it down so everything is tight, but as soon as I protect the workbook, I get a "Run-time error '1004': Method 'Visible' of object'_Worksheet' failed. Thank you!

Code:
Sub Print_Quote()
    Dim CurVIs As Long
    Dim ws As Worksheet
    For Each ws In Sheets(Array("Sheet Name"))
        With ws
            CruVis = .Visible
            If CurVIs >= 0 Then
                .Visible = xlSheetVisible
                .ExportAsFixedFormat _
                Type:=xlTypePDF, _
                Filename:="C:\File Name.pdf", _
                Quality:=xlQualityStandard, _
                IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, _
                OpenAfterPublish:=True
                .Visible = xlSheetHidden
            End If
        End With
    Next ws
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
It looks like your code will make all the sheets hidden, or try to. there must be at least one visible sheet.
 
Upvote 0
Thanks SpillerBD

There is a visible sheet - the calculation sheet. The print button code is pulling from a hidden sheet to "print" an adobe file that can be saved and/or printed. It works as expected until I choose to protect workbook, then it errors out. I think I need some kind of Unprotect/Protect script, but I don't know how to do that with an entire workbook.

Jenny
 
Upvote 0

Forum statistics

Threads
1,215,388
Messages
6,124,658
Members
449,177
Latest member
Sousanna Aristiadou

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