Consulting

Results 1 to 7 of 7

Thread: Code to Group Worksheets when Printing and Print Preview - 2003 vs 2010

  1. #1
    VBAX Regular
    Joined
    Oct 2008
    Posts
    69
    Location

    Code to Group Worksheets when Printing and Print Preview - 2003 vs 2010

    have been using the following code to group worksheets (and subsequently ungroup) to print (and print preview). This was developed for Excel 2003 and worked well. It works well to PRINT in Excel 2010, but doesn't work at all for the print preview function. What changes do I need to make to group the print preview as well?

    I substituted Sheet1, Sheet2... for the actual sheet names in the example

    To Group:

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Sheets(Array("Sheet1")).Select
    Cancel = True
    Sheets(Array("Sheet2", "Sheet3", "Sheet4", " Sheet5", " Sheet6")).Select
    Cancel = False
    Application.OnTime Now, "AfterPrint"
    End Sub


    To Ungroup:


    Private Sub AfterPrint()
    'code to run after the print event
    Sheets("Sheet2").Select
        Range("A4").Select
    End Sub

  2. #2
    VBAX Regular
    Joined
    Oct 2008
    Posts
    69
    Location
    Can anyone help me out with this?

    I am really taking a huge dislike to the excel 2010...(I'm sure I am not alone on that)

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This works fine for me in 2010

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
        Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6")).Select
        Application.OnTime Now, "AfterPrint"
    End Sub
    BTW, shouldn't AfterPrint be a Public procedure?
    ____________________________________________
    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

  4. #4
    VBAX Regular
    Joined
    Oct 2008
    Posts
    69
    Location
    Quote Originally Posted by xld View Post
    This works fine for me in 2010

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
        Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6")).Select
        Application.OnTime Now, "AfterPrint"
    End Sub
    BTW, shouldn't AfterPrint be a Public procedure?
    It works for print, but I can't get it to work for print preview..
    I don't know about your question...perhaps it should be!

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What part doesn't work for you? It all worked for me (after making AfterPrint public).
    ____________________________________________
    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

  6. #6
    VBAX Regular
    Joined
    Oct 2008
    Posts
    69
    Location
    The grouping for print preview didn't work...I will try making the AfterPrint Public..I am not sure how that would affect the Print Preview function.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It won't, it makes the tidy-up work.
    ____________________________________________
    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
  •