Consulting

Results 1 to 4 of 4

Thread: Convert workbook code to worksheet code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Convert workbook code to worksheet code

    Hi guys!

    I use this code in my workbook (found it on internet ), to hide specific cells of worksheet - "Sheet1" from printing.

    [vba]Private Sub Workbook_BeforePrint(Cancel As Boolean)
    If Me.ActiveSheet.Name = "Sheet1" _
    Then Cancel = True Else Exit Sub

    Application.ScreenUpdating = False
    Application.EnableEvents = False '

    Dim iArchive As New Collection
    Dim iSource As Range, iCell As Range
    Set iSource = Me.ActiveSheet.Range("B1:AJ1, B2:AJ2, U3:AJ3, U4:AJ4, AD6:AJ6, AD7:AJ7, B8:AB8, B14:AJ14, B20:AJ20, B22:AJ22, B24:AJ24, B26:AJ26, B45:AJ45, B47:AJ47, B55:AJ55, B57:AJ57, B59:AJ59")
    For Each iCell In iSource
    With iCell
    iArchive.Add .Font.Color, .Address
    .Font.Color = .Interior.Color
    End With
    Next
    Me.ActiveSheet.PrintOut 'Copies:=1
    For Each iCell In iSource
    iCell.Font.Color = iArchive(iCell.Address)
    Next

    Application.EnableEvents = True '
    Application.ScreenUpdating = True
    End Sub[/vba]
    Now i need to add 2-3 additional worksheets to my workbook with their own, hidden from printing cell's. How do I convert this code from workbook, to each separate worksheet? Or, how to add additional worksheet's, in to this code?
    Last edited by Nemesis696; 06-27-2011 at 07:39 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •