Results 1 to 3 of 3

One Button Print Current Page Macro

Threaded View

  1. #1
    Registered User
    Join Date
    03-27-2017
    Location
    Penticton, BC
    MS-Off Ver
    2016
    Posts
    35

    One Button Print Current Page Macro

    Hi Experts!

    I have an excel worksheet that we add daily information to. Each day is pre-broken into individual pages. It's huge (one day I will turn it into a proper form but for now this will do).

    I have placed a button at the top of the page (that is frozen at the top) with the intention that the user can enter the info required into that day's page and then push the button to print off just that one sheet.

    I have placed this macro code (found on various help sites - every else seems to love this code) but when I push the button is says Subscript out of Range. My Macro game isn't strong enough to look at the code and have that eureka moment. Any thoughts? I am using Excel 2016.



    Public Sub Print_Page_of_ActiveCell()
        Dim ActiveRow As Long, ActiveCol As Integer
        Dim iHPBs As Integer, iVPBs As Integer
        Dim iRow As Integer, iCol As Integer, iPage As Integer
         
        ActiveRow = ActiveCell.Row
        ActiveCol = ActiveCell.Column
        ActiveSheet.UsedRange
        If IsEmpty(ActiveCell.SpecialCells(xlCellTypeLastCell)) Then _
        ActiveCell.SpecialCells(xlCellTypeLastCell).FormulaR1C1 = " "
        If ActiveRow > ActiveCell.SpecialCells(xlCellTypeLastCell).Row Or _
        ActiveCol > ActiveCell.SpecialCells(xlCellTypeLastCell).Column Then _
        Exit Sub
         
        With ActiveSheet
            iHPBs = .HPageBreaks.Count
            iVPBs = .VPageBreaks.Count
            If iHPBs = 0 And iVPBs = 0 Then GoTo PrintSheet
    Horizontal:
            For iRow = iHPBs To 1 Step -1
                If .HPageBreaks(iRow).Location.Row <= ActiveRow Then GoTo Vertical
            Next iRow
    Vertical:
            For iCol = iVPBs To 1 Step -1
                If .VPageBreaks(iCol).Location.Column <= ActiveCol Then GoTo PrintSheet
            Next iCol
    PrintSheet:
            iPage = (iRow + 1) + (iCol * (iHPBs + 1))
            .PrintOut From:=iPage, To:=iPage
            MsgBox "Printing page " & iPage
        End With
        If ActiveCell.SpecialCells(xlCellTypeLastCell).FormulaR1C1 = " " Then _
        Selection.SpecialCells(xlCellTypeLastCell).ClearContents
    
    End Sub


    Many thanks!
    Suzy
    Last edited by BBFDSue; 03-29-2017 at 01:02 PM. Reason: as per sintek's instruction

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Print current page with active cell with VBA code Excel 2010
    By ruznemat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2017, 08:42 AM
  2. how to make macro button to print page that has the active cell only?
    By meonly123 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-22-2015, 11:05 AM
  3. Disabled print toolbar and menu but Print Macro button cannot print also...
    By zein97 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2014, 01:42 PM
  4. click to run, print current page then copy and past cells in to next avalable space.
    By ryannoble in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-31-2013, 05:27 PM
  5. [SOLVED] Print only current page! Not all 47 pages when print button is pressed?
    By Margate in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-11-2013, 10:06 AM
  6. How to print the current page containing active cells?
    By smart89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-25-2007, 04:14 AM
  7. Button to print non-active page - How?
    By Bafa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2006, 11:53 PM

Tags for this Thread

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