+ Reply to Thread
Results 1 to 5 of 5

Excel 2013, page-numbers on different printing-options

Hybrid View

  1. #1
    Registered User
    Join Date
    09-30-2016
    Location
    Munich, Germany
    MS-Off Ver
    2013
    Posts
    17

    Excel 2013, page-numbers on different printing-options

    Hello all,

    I have a workboot with several sheets and each sheet can be multiple papers when printed out.
    I added a footer with &[Page]/&[Pages] to show e.g. 1/3.
    However this behaves differently depending on how I print.
    If I only print the active sheet then I get 1/3, 2/3, 3/3, however if I print the whole book then I get e.g. 1/17, 2/17, etc.

    How can I get Excel to just calculate the page-numbers based on individual sheets instead of dependencies of the print-process?

    Cheers,

    Moadll

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,757

    Re: Excel 2013, page-numbers on different printing-options

    That's just not how Excel works. One option is to create a macro to print the whole file, which will really print one sheet at a time.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    09-30-2016
    Location
    Munich, Germany
    MS-Off Ver
    2013
    Posts
    17

    Re: Excel 2013, page-numbers on different printing-options

    Hello Jeff,

    that's unfortunate. The macro itself would be a theoretical way, however as the file will be handled any "random" person that's just asking for trouble. "Why should I click on something else if I have the print-button there...?"

    I guess I'll have to got the old-fashioned "brute force and ignorance approach" and create text-boxes with the appropriate content when I create the file.

    Cheers,

    Martin

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,757

    Re: Excel 2013, page-numbers on different printing-options

    There is a VBA event called BeforePrint that can trap the user's Print command. If the user presses the Print button, the macro can replace that with something else. This does that and prints each sheet individually. The user never knows the difference.

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    
       Dim WS As Worksheet
       
       Cancel = True
       
       For Each WS In Worksheets
          WS.PrintOut
       Next WS
       
    End Sub

  5. #5
    Registered User
    Join Date
    09-30-2016
    Location
    Munich, Germany
    MS-Off Ver
    2013
    Posts
    17

    Post Re: Excel 2013, page-numbers on different printing-options

    Hello 6StringJazzer,

    thanks for the pointer, that helped. I had to put in a bit of stuff additionally to catch the difference between the original print and the print of the individual work-sheets as otherwise every print would have been cancelled.
    It looks like that as total:

    Dim WS_Number As Long
    Dim CurrentSheet As Long
    Dim BolIndividualPrint As Boolean
    Dim BolPrintDone As Boolean
    Private Sub SheetPrint()
        Dim WS As Worksheet
        For Each WS In Worksheets
            If CurrentSheet = WS_Number - 1 Then
                BolIndividualPrint = False
                BolPrintDone = True
            End If
            WS.PrintOut
            CurrentSheet = CurrentSheet + 1
        Next WS
    End Sub
    
    
    
    Private Sub Workbook_BeforePrint(Cancel As Boolean)
       If Not BolIndividualPrint Then
          Cancel = True
          If Not BolPrintDone Then
            WS_Number = Worksheets.Count
            CurrentSheet = 0
            BolIndividualPrint = True
            Call SheetPrint
          Else
            BolPrintDone = False
          End If
       End If
    End Sub
    As additional icing on the cake that code needs to be placed into a generated file which is only used for the printout. For that I went for the programmatic editing of that generated file:
    Sub AddSht_AddCode()
        Dim wb As Workbook
        Dim xPro As VBIDE.VBProject
        Dim xCom As VBIDE.VBComponent
        Dim xMod As VBIDE.CodeModule
        Dim xLine As Long
    
        With wb
            Set xPro = .VBProject        
            Set xCom = xPro.VBComponents("ThisWorkbook")
            Set xMod = xCom.CodeModule
    
            With xMod
                xLine = .CountOfLines + 1
                .InsertLines xLine, "Dim WS_Number As Long"
                xLine = xLine + 1
                <...>
                .InsertLines xLine, "Private Sub SheetPrint()"
                xLine = xLine + 1
                .InsertLines xLine, "    Dim WS As Worksheet"
                xLine = xLine + 1
                <...>
                xLine = .CreateEventProc("BeforePrint", "Workbook")
                xLine = xLine + 1
                .InsertLines xLine, "   If Not BolIndividualPrint Then"
                xLine = xLine + 1
                <...>
            End With
        End With
        ActiveWorkbook.Save
    end sub
    So thanks a lot for the pointer.

    Cheers,

    Moadll

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Excel 2013 - Adjust Excel Sheet Protection options to allow users to make some changes
    By aLi3nZ in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-21-2017, 12:54 AM
  2. [SOLVED] continuous page numbers when printing to PDF via VBA
    By Matthew55 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-09-2017, 02:58 PM
  3. Printing PDFs file with Excel Sheets With Page Numbers
    By reachharry in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-24-2014, 10:59 AM
  4. Printing selected sheets and Page numbers
    By BPat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-06-2011, 10:05 AM
  5. printing page numbers in sheet
    By spec1968 in forum Excel General
    Replies: 5
    Last Post: 03-18-2009, 04:19 AM
  6. Printing Page numbers in Excel sheet
    By bhargav in forum Excel General
    Replies: 1
    Last Post: 01-10-2007, 08:25 AM
  7. [SOLVED] Printing and Page numbers
    By Darin Kramer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2005, 12:06 PM

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