Consulting

Results 1 to 4 of 4

Thread: plz Help: allow certen sheet to be printed with condition

  1. #1

    plz Help: allow certen sheet to be printed with condition

    Dear Sirs,

    There are 20 sheets say Sh1 to Sh20. How can I disable print if i'm in not allowed sheets.
    Say I wanna print Sh1, Sh4, Sh9, Sh12 & Sh15 only
    When any of these allowed sheets and if I press Print Botton, there is a condition as follow:

    If I press Print when Sh1 or Sh9 or Sh12 or Sh15 is active then use this code

    [vba]

    Sub PrintSheets_Condition1()
    Dim aShtLst As Variant
    aShtLst = Array("Sh1", "Sh9", "Sh12", "Sh15")
    ThisWorkbook.Sheets(aShtLst).PrintOut
    End Sub[/vba]

    If I press Print when Sh4 is active then use this code

    [vba]

    Sub PrintSheets_Condition2()
    Dim aShtLst As Variant
    aShtLst = Array("Sh4", "Sh9", "Sh12", "Sh15")
    ThisWorkbook.Sheets(aShtLst).PrintOut
    End Sub[/vba]

    As well as in each of these sheets (i.e. [COLOR=#000000]Sh1, Sh4, Sh9, Sh12 & Sh15) there will be a shape to run these conditions
    i.e. shape to run PrintSheets_Condition1 in Sh1, Sh9, Sh12, Sh15

    shape to run PrintSheets_Condition2 in Sh4

    Thank you
    Last edited by Bob Phillips; 03-09-2012 at 05:07 AM. Reason: Added VBA tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Untested

    [vba]

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Dim aShtLst As Variant
    Select Case ActiveSheet.Name

    Case "Sh1", "Sh9", "Sh12", "Sh15"

    aShtLst = Array("Sh1", "Sh9", "Sh12", "Sh15")

    Case "Sh4"

    aShtLst = Array("Sh4", "Sh9", "Sh12", "Sh15")
    End Select

    ThisWorkbook.Sheets(aShtLst).PrintOut
    End Sub[/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    It is not working with me


    Quote Originally Posted by xld
    Untested

    [vba]

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Dim aShtLst As Variant
    Select Case ActiveSheet.Name

    Case "Sh1", "Sh9", "Sh12", "Sh15"

    aShtLst = Array("Sh1", "Sh9", "Sh12", "Sh15")

    Case "Sh4"

    aShtLst = Array("Sh4", "Sh9", "Sh12", "Sh15")
    End Select

    ThisWorkbook.Sheets(aShtLst).PrintOut
    End Sub[/vba]

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That doesn't tell me much does it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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