+ Reply to Thread
Results 1 to 25 of 25

hiding sheets but still letting macros run when printing hidden sheets

Hybrid View

stevesunfold hiding sheets but still... 11-10-2008, 04:35 PM
royUK You need to unhide the sheet... 11-10-2008, 04:40 PM
stevesunfold thanks for the reply roy how... 11-10-2008, 04:53 PM
stevesunfold if anyone could help it would... 11-10-2008, 05:57 PM
Paul Steve, does this work for... 11-10-2008, 06:16 PM
stevesunfold hi pjoaquin thanks for the... 11-10-2008, 06:26 PM
Paul I would think you could just... 11-10-2008, 07:04 PM
stevesunfold hiya im getting this really... 11-10-2008, 07:36 PM
pr4t3ek you may need to restart your... 11-10-2008, 08:04 PM
Paul You can add this at the... 11-10-2008, 10:35 PM
stevesunfold hiya it still does it but... 11-11-2008, 03:31 AM
royUK This has tidied up the code,... 11-11-2008, 05:04 AM
stevesunfold hi roy i get an instant... 11-11-2008, 01:22 PM
royUK What is SelectSheets? 11-11-2008, 04:57 AM
royUK Maybe if you use GoTo ... 11-11-2008, 02:23 PM
stevesunfold hi roy that works well and... 11-11-2008, 02:57 PM
royUK It should select the sheets... 11-11-2008, 03:04 PM
stevesunfold select sheets brings up a pop... 11-11-2008, 03:14 PM
stevesunfold bump bump bump 11-12-2008, 01:28 PM
royUK I think that macro is causing... 11-12-2008, 02:39 PM
  1. #1
    Forum Contributor
    Join Date
    06-23-2007
    Posts
    690

    hiding sheets but still letting macros run when printing hidden sheets

    hi guys
    i have a workbook that has the following sheets

    working sheet
    job sheet
    receipt of deposit letter
    completion sheet
    delivery note
    delivery note (2)
    odd
    even
    t&t
    glass
    ggf

    i want to hide every sheet except the working sheet.
    I have tried this but the macros bring up an error when i run the macro

    my macros involve printing certain pages dependng on what button is pressed

    i get an error whatever
    how do i stop this

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You need to unhide the sheet

    Application.ScreenUpdating = False
        With Worksheets("receipt of deposit letter")
            .Visible = xlSheetVisible
            .PrintOut
            .Visible = xlSheetVeryHidden
        End With
        Application.ScreenUpdating = True
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    06-23-2007
    Posts
    690
    thanks for the reply roy
    how ould i incorporate that code into this?

    Sub PRINTSUPPLYONLY()
        Select Case _
               MsgBox("HAVE YOU SELECTED THE SYSTEM IN THE DELIVERY SHEET?", _
                      vbYesNo Or vbQuestion Or vbDefaultButton1, "Delivery sheet")
              
            Case vbYes
      Sheets("Delivery note").Select
                MsgBox "THESE ARE ALL TO BE SENT TO THE CUSTOMER " & _
        Chr(10) & "PLEASE INSERT 1 SHEET OF HEADED PAPER!"
                Sheets("Receipt of deposit letter").Select
                ActiveWindow.SelectedSheets.PrintOut Copies:=1
                Sheets("glass").Select
                ActiveWindow.SelectedSheets.PrintOut Copies:=1
                Sheets("Ggf").Select
                ActiveWindow.SelectedSheets.PrintOut Copies:=1
        Call SelectSheets
            Case vbNo
    Sheets("Delivery note").Select
        Range("B16").Select
                Exit Sub
        End Select
                MsgBox "THESE ARE ALL FOR THE FILE!"
                Sheets("Job sheet").Select
                ActiveWindow.SelectedSheets.PrintOut Copies:=1
                Sheets("Receipt of deposit letter").Select
                ActiveWindow.SelectedSheets.PrintOut Copies:=1
                Sheets("delivery note").Select
                ActiveWindow.SelectedSheets.PrintOut Copies:=1
        
        MsgBox "INPUT DATA INTO BOOK"
        
        Sheets("working sheet").Select
                Range("D1").Select
                
    End Sub
    many thanks

  4. #4
    Forum Contributor
    Join Date
    06-23-2007
    Posts
    690
    if anyone could help it would be appreciated

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Steve, does this work for you?
    Sub PRINTSUPPLYONLY()
    Application.ScreenUpdating = False
    Select Case MsgBox("HAVE YOU SELECTED THE SYSTEM IN THE DELIVERY SHEET?", _
        vbYesNo + vbQuestion + vbDefaultButton1, "Delivery sheet")
        Case vbYes
            MsgBox "THESE ARE ALL TO BE SENT TO THE CUSTOMER " & _
                Chr(10) & "PLEASE INSERT 1 SHEET OF HEADED PAPER!"
            Sheets("Receipt of deposit letter").Visible = True
            Sheets("Receipt of deposit letter").PrintOut
            Sheets("Receipt of deposit letter").Visible = False
            Sheets("glass").Visible = True
            Sheets("glass").PrintOut
            Sheets("glass").Visible = False
            Sheets("Ggf").Visible = True
            Sheets("Ggf").PrintOut
            Sheets("Ggf").Visible = False
            Call SelectSheets
        Case vbNo
            Sheets("delivery note").Range("B16").Select
            Exit Sub
    End Select
    
    MsgBox "THESE ARE ALL FOR THE FILE!"
    Sheets("Job sheet").Visible = True
    Sheets("Job sheet").PrintOut
    Sheets("Job sheet").Visible = False
    Sheets("Receipt of deposit letter").Visible = True
    Sheets("Receipt of deposit letter").PrintOut
    Sheets("Receipt of deposit letter").Visible = False
    Sheets("delivery note").Visible = True
    Sheets("delivery note").PrintOut
    Sheets("delivery note").Visible = False
    
    MsgBox "INPUT DATA INTO BOOK"
    Sheets("working sheet").Range("D1").Select
    Application.ScreenUpdating = False
    End Sub
    Last edited by Paul; 11-10-2008 at 06:20 PM.

  6. #6
    Forum Contributor
    Join Date
    06-23-2007
    Posts
    690
    hi pjoaquin
    thanks for the reply
    it works except for the fact that if i select no it shows the delivery note tab but doesnt mae it the active sheet
    so i guess i should leave that particualr sheet visible?

    what it should do is take me to sheet "delivery note" cell b16
    asking me to input what system im using

    steve
    Last edited by VBA Noob; 11-10-2008 at 06:44 PM.

  7. #7
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    I would think you could just add:
    Sheets("delivery note").Visible = True
    immediately after the 'Case vbNo' statement. This, of course, would leave it open after the user edited the cell, so you may as well leave it visible.

  8. #8
    Forum Contributor
    Join Date
    06-23-2007
    Posts
    690
    hiya
    im getting this really annoying pop up half way through the macro that says "all worksheets are empty" and then waits for you to click ok and then progresses is there anyway to stop this?

    regards

  9. #9
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    you may need to restart your comp...
    --
    Regards
    PD

    ----- Don't Forget -----

    1. Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks

    2. Thank those who have helped you by Clicking the scales above each post.

    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  10. #10
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    You can add this at the beginning:
    Application.DisplayAlerts = False
    and this at the end:
    Application.DisplayAlerts = True
    BUT- this message is probably just telling you that there's nothing to print on one or more of the worksheet(s) in question. You may want to step through the code line-by-line to see which sheets are causing this (if it matters to you).

  11. #11
    Forum Contributor
    Join Date
    06-23-2007
    Posts
    690
    hiya

    it still does it but thats not really a big worry
    the problem is that it doesnt do the call SelectSheets part of the macro

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    This has tidied up the code, but you need to test it. I can't see why you are calling a macro called SElectSheets when the sheets are selected.
    Option Explicit
    Sub PRINTSUPPLYONLY()
        With Application
            .DisplayAlerts = False
            .ScreenUpdating = False
            Select Case _
                   MsgBox("HAVE YOU SELECTED THE SYSTEM IN THE DELIVERY SHEET?", _
                          vbYesNo Or vbQuestion Or vbDefaultButton1, "Delivery sheet")
    
                Case vbYes
                    Sheets(Array("Delivery note", "Receipt of deposit letter", "glass", "Ggf")).Select
                    MsgBox "THESE ARE ALL TO BE SENT TO THE CUSTOMER " & _
                           Chr(10) & "PLEASE INSERT 1 SHEET OF HEADED PAPER!"
                    ActiveWindow.SelectedSheets.PrintOut Copies:=1
                   Call SelectSheets    'what does this do?
                Case vbNo
                    Sheets("Delivery note").Range("B16").Select
                    Exit Sub
            End Select
            MsgBox "THESE ARE ALL FOR THE FILE!"
            Sheets(Array("Job sheet", "Receipt of deposit letter", "delivery note")).PrintOut Copies:=1
            ActiveWindow.SelectedSheets.PrintOut Copies:=1
    
            MsgBox "INPUT DATA INTO BOOK"
    
            .Goto (Sheets("working sheet").Range("D1"))
            .DisplayAlerts = True
            .ScreenUpdating = True
            End With
        End Sub

  13. #13
    Forum Contributor
    Join Date
    06-23-2007
    Posts
    690
    hi roy
    i get an instant error if i click no and it highlights this line

    Sheets("Delivery note").Range("B16").Select
    the call selectsheets

    is a way of checking a box that requires me to select any of 3 boxes that i may need and it prints off the selected sheet(s)
    Last edited by stevesunfold; 11-11-2008 at 02:02 PM.

  14. #14
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Notice the capitalization of "Delivery note". Based on other code, my guess is your worksheet name is actually "delivery note".

  15. #15
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    What is SelectSheets?

  16. #16
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Maybe if you use GoTo
    Option Explicit
    Option Compare Text
    Sub PRINTSUPPLYONLY()
        With Application
            .DisplayAlerts = False
            .ScreenUpdating = False
            Select Case _
                   MsgBox("HAVE YOU SELECTED THE SYSTEM IN THE DELIVERY SHEET?", _
                          vbYesNo Or vbQuestion Or vbDefaultButton1, "Delivery sheet")
    
                Case vbYes
                    Sheets(Array("Delivery note", "Receipt of deposit letter", "glass", "Ggf")).Select
                    MsgBox "THESE ARE ALL TO BE SENT TO THE CUSTOMER " & _
                           Chr(10) & "PLEASE INSERT 1 SHEET OF HEADED PAPER!"
                    ActiveWindow.SelectedSheets.PrintOut Copies:=1
                   Call SelectSheets    'what does this do?
                Case vbNo
                    .Goto (Sheets("Delivery note").Range("B16"))
                    Exit Sub
            End Select
            MsgBox "THESE ARE ALL FOR THE FILE!"
            Sheets(Array("Job sheet", "Receipt of deposit letter", "delivery note")).PrintOut Copies:=1
            ActiveWindow.SelectedSheets.PrintOut Copies:=1
    
            MsgBox "INPUT DATA INTO BOOK"
    
            .Goto (Sheets("working sheet").Range("D1"))
            .DisplayAlerts = True
            .ScreenUpdating = True
            End With
        End Sub

  17. #17
    Forum Contributor
    Join Date
    06-23-2007
    Posts
    690
    hi roy
    that works well and takes me to the delivery note tab but when i click back OR if i click yes i get this message

    run time error 1004
    select method of sheets class failed

  18. #18
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    It should select the sheets in the array & print them.
    I don't think that you have said what SelectSheets does.

  19. #19
    Forum Contributor
    Join Date
    06-23-2007
    Posts
    690
    select sheets brings up a pop up asking to select
    odd
    even
    t&t

    it has checkboxes that allows me to select any or all of them and then prints the checked sheets

    and the error code highlights this line
    Sheets(Array("Delivery note", "Receipt of deposit letter", "glass", "Ggf")).Select
    select sheets is actually this code if it helps

    Option Explicit
    
    Sub SelectSheets()
        Dim i As Integer
        Dim TopPos As Integer
        Dim SheetCount As Integer
        Dim PrintDlg As DialogSheet
        Dim CurrentSheet As Worksheet
        Dim cb As CheckBox
        Application.ScreenUpdating = False
    
    '   Check for protected workbook
        If ActiveWorkbook.ProtectStructure Then
            MsgBox "Workbook is protected.", vbCritical
            Exit Sub
        End If
    
    '   Add a temporary dialog sheet
        Set CurrentSheet = ActiveSheet
        Set PrintDlg = ActiveWorkbook.DialogSheets.Add
    
        SheetCount = 0
    
    '   Add the checkboxes
    
        TopPos = 40
        For i = 1 To ActiveWorkbook.Worksheets.Count
            Set CurrentSheet = ActiveWorkbook.Worksheets(i)
    '       Skip empty sheets and hidden sheets
            Select Case CurrentSheet.Name
                Case "working sheet"
                Case "Job Sheet"
                Case "Receipt of deposit letter"
                Case "Completion sheet"
                Case "Delivery note"
                Case "Delivery note (2)"
                Case "glass"
                Case "Ggf"
            Case Else
            If Application.CountA(CurrentSheet.Cells) <> 0 And _
                CurrentSheet.Visible Then
                SheetCount = SheetCount + 1
                PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
                    PrintDlg.CheckBoxes(SheetCount).Text = _
                        CurrentSheet.Name
                TopPos = TopPos + 13
            End If
            End Select
        Next i
            
    '   Move the OK and Cancel buttons
        PrintDlg.Buttons.Left = 240
    
    '   Set dialog height, width, and caption
        With PrintDlg.DialogFrame
            .Height = Application.Max _
                (68, PrintDlg.DialogFrame.Top + TopPos - 34)
            .Width = 430
            .Caption = "PLEASE SELECT THE OPERATING SHEETS FOR THE REUIRED NUMBER OF DOORS"
    
        End With
    
    '   Change tab order of OK and Cancel buttons
    '   so the 1st option button will have the focus
        PrintDlg.Buttons("Button 2").BringToFront
        PrintDlg.Buttons("Button 3").BringToFront
    
    '   Display the dialog box
        CurrentSheet.Activate
        Application.ScreenUpdating = True
        If SheetCount <> 0 Then
            If PrintDlg.Show Then
                For Each cb In PrintDlg.CheckBoxes
                    If cb.Value = xlOn Then
                        Worksheets(cb.Caption).Activate
                        ActiveSheet.PrintOut
    '                   ActiveSheet.PrintPreview 'for debugging
    
                    End If
                Next cb
            End If
        Else
            MsgBox "All worksheets are empty."
        End If
    
    '   Delete temporary dialog sheet (without a warning)
        Application.DisplayAlerts = False
        PrintDlg.Delete
    
    '   Reactivate original sheet
        CurrentSheet.Activate
    End Sub
    Last edited by stevesunfold; 11-11-2008 at 03:20 PM.

  20. #20
    Forum Contributor
    Join Date
    06-23-2007
    Posts
    690
    bump bump bump

  21. #21
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I think that macro is causing the problem. It will certainly print sheets twice.

  22. #22
    Forum Contributor
    Join Date
    06-23-2007
    Posts
    690
    no roy its not that

    the code that you gave me

    now doesnt bring up the pop up of selectsheets

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1