Print dialogue by hiding row 13

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
Hi anyone,

How could i write a mcaro code that would show the print dialogue by hiding row 13 of the active sheet if its not hidden.

If its hidden; will show the dialog by not doing any action.

Any help on this would be kindly appreciated.

Thanks in advance.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Code:
[COLOR="Blue"]Private[/COLOR] [COLOR="Blue"]Sub[/COLOR] Workbook_BeforePrint(Cancel [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Boolean[/COLOR])
    [COLOR="Blue"]With[/COLOR] Activsheet.Rows(13).EntireRow
        [COLOR="Blue"]If[/COLOR] .Hidden = [COLOR="Blue"]False[/COLOR] [COLOR="Blue"]Then[/COLOR]
            .Hidden = [COLOR="Blue"]True[/COLOR]
        [COLOR="Blue"]Else[/COLOR]
            Cancel = [COLOR="Blue"]True[/COLOR]
        [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]If[/COLOR]
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
Does this mean each time the print dialogue is open the row 13 gets hidden on any active sheet?

My concern is that I have some sheets where I don't want to hide row 13 but open print dialogue?
 
Upvote 0
Replace and add sheet names in Array function where row 13 must be hidden.

Code:
[COLOR="Blue"]Private[/COLOR] [COLOR="Blue"]Sub[/COLOR] Workbook_BeforePrint(Cancel [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Boolean[/COLOR])

    [COLOR="Blue"]Dim[/COLOR] i [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Integer[/COLOR], arr [COLOR="Blue"]As[/COLOR] Variant
    
    arr = Array("Sheet1", "Sheet2", "Sheet3")

    [COLOR="Blue"]For[/COLOR] i = [COLOR="Blue"]LBound[/COLOR](arr) [COLOR="Blue"]To[/COLOR] [COLOR="Blue"]UBound[/COLOR](arr)
        [COLOR="Blue"]If[/COLOR] arr(i) = ActiveSheet.Name [COLOR="Blue"]Then[/COLOR]
            [COLOR="Blue"]If[/COLOR] .Hidden = [COLOR="Blue"]False[/COLOR] [COLOR="Blue"]Then[/COLOR]
                .Hidden = [COLOR="Blue"]True[/COLOR]
            [COLOR="Blue"]Else[/COLOR]
                ActiveSheet.PrintPreview
            [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]If[/COLOR]
        [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]If[/COLOR]
    [COLOR="Blue"]Next[/COLOR]

[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
In your second code you haven't mention the row to be hidden this gives me debug message.

Having this situation where should I place the line

With Activsheet.Rows(13).EntireRow in the second code?</pre>
 
Upvote 0
Sorry... Correction:
Code:
[COLOR="Blue"]Private[/COLOR] [COLOR="Blue"]Sub[/COLOR] Workbook_BeforePrint(Cancel [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Boolean[/COLOR])

    [COLOR="Blue"]Dim[/COLOR] i [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Integer[/COLOR], arr [COLOR="Blue"]As[/COLOR] Variant
    
    arr = Array("Sheet1", "Sheet2", "Sheet3")

    [COLOR="Blue"]With[/COLOR] ActiveSheet.Rows(13).EntireRow
        [COLOR="Blue"]For[/COLOR] i = [COLOR="Blue"]LBound[/COLOR](arr) [COLOR="Blue"]To[/COLOR] [COLOR="Blue"]UBound[/COLOR](arr)
            [COLOR="Blue"]If[/COLOR] arr(i) = ActiveSheet.Name [COLOR="Blue"]Then[/COLOR]
                [COLOR="Blue"]If[/COLOR] .Hidden = [COLOR="Blue"]False[/COLOR] [COLOR="Blue"]Then[/COLOR]
                    .Hidden = [COLOR="Blue"]True[/COLOR]
                [COLOR="Blue"]Else[/COLOR]
                    ActiveSheet.PrintPreview
                [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]If[/COLOR]
            [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]If[/COLOR]
        [COLOR="Blue"]Next[/COLOR]
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]

[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
I'm sorry but I don't see any effect of this code on my workbook. I mean it does not hide row 13 and show the print dialog. Instead it shows the print dialogue but does not hide the row.

What may be the reason for this?
 
Upvote 0

Forum statistics

Threads
1,224,531
Messages
6,179,379
Members
452,907
Latest member
Roland Deschain

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