Print with Hide, then after print, unhide everything

RMXByker

New Member
Joined
Apr 1, 2010
Messages
38
I have a macro attached to an icon that will unlock the sheet, hide certain rows and column, bring up the application dialog to print and the unhide everything upon the print dialog box being closed and lock the sheet back up. Problem is, the print dialog doesn't seem to acutally print. Any ideas? I tried to label all the code to explain what my intent is. Hopefully this helps.

Code:
Sub PrintwithHide()

 ActiveSheet.Unprotect Password:="TESTING"
 
'Hide the Columns
    Dim C As Range


    For Each C In Range("AA6:BW6").Cells
        If C.Value = "TP-" Then
            C.EntireColumn.Hidden = True


        End If
    Next C
    
'Hide the Rows
    Dim d As Range


    For Each d In Range("A10:A50").Cells
        If d.Value = "" Then
            d.EntireRow.Hidden = True


        End If
    Next d
    
'Hide the unnecessary Columns
    Range("H:H,I:I,J:J,K:K,L:L,M:M,N:N,O:O,P:P,Q:Q").Select
    Range("Q5").Activate
    Selection.EntireColumn.Hidden = True
    Range("A10").Select


'Print
 Application.Dialogs(xlDialogPrinterSetup).Show
 
'Unhidethe unnecessary Columns
    Columns("D:Z").Select
    Range("Z5").Activate
    Selection.EntireColumn.Hidden = False
    ActiveWindow.LargeScroll ToRight:=-1
    Range("A10").Select
 
'Unhide the Columns
    Dim e As Range


    For Each e In Range("AA6:BW6").Cells
        If e.Value = "TP-" Then
            e.EntireColumn.Hidden = False


        End If
    Next e
    
 'Unhide the Rows
    Dim f As Range


    For Each f In Range("A10:A50").Cells
        If f.Value = "" Then
            f.EntireRow.Hidden = False


        End If
    Next f
    
 ActiveSheet.Protect Password:="TESTING", AllowInsertingRows:=True, AllowDeletingRows:=True


End Sub

Thanks in advance...
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Problem solved by inserting this code for the print dialog in case anyone else comes across the issue.

Code:
'Print If Application.Dialogs(xlDialogPrinterSetup).Show = True Then
      ActiveWindow.SelectedSheets.PrintOut
End If
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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