Results 1 to 2 of 2

Thread: VBA Macro To Print With Custom From And To Page Numbers

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    37
    Rep Power
    0

    VBA Macro To Print With Custom From And To Page Numbers

    hi expert..

    i hope you can give solution about my code macro, below :

    Code:
    Sub PrintForms()
        Dim StartRow As Integer
        Dim EndRow As Integer
        Dim Msg As String
        Dim i As Integer
        
        Sheets("Resume").Activate
        StartRow = Range("StartRow")
        EndRow = Range("EndRow")
        
        If StartRow > EndRow Then
            Msg = "ERROR" & vbCrLf & "The starting row must be less than the ending row!"
            MsgBox Msg, vbCritical, APPNAME
        End If
        
        For i = StartRow To EndRow
            Range("RowIndex") = i
            If Range("Preview") Then
                ActiveSheet.PrintPreview
            Else
                ActiveSheet.PrintOut
            End If
        Next i
    End Sub
    my question, how can modify/adding/insert new code, that macro have can be printing multiple pages e.g. print 1-4 pages or 6-12 pages, etc...
    my problem with code that above, only running print one by one.....

    i'am newbie about macro...

    thanks...superman.....



    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=bRd4mJglWiM&lc=UgxRmh2gFhpmHNnPemR4AaABAg. A0opm95t2XEA0q3KshmuuY
    https://www.youtube.com/watch?v=bRd4mJglWiM&lc=UgxRmh2gFhpmHNnPemR4AaABAg
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=314837#p314837
    https://www.eileenslounge.com/viewtopic.php?f=21&t=40701&p=314836#p314836
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314621#p314621
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314619#p314619
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314600#p314600
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314599#p314599
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314274#p314274
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314229#p314229
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314195#p314195
    https://www.eileenslounge.com/viewtopic.php?f=36&t=39706&p=314110#p314110
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40597&p=314081#p314081
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40597&p=314078#p314078
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=314062#p314062
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40597&p=314054#p314054
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=313971#p313971
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=313909#p313909
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40574&p=313879#p313879
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 03-11-2024 at 02:18 PM.

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    The first two arguments for PrintOut are [From] and [To]

    So your code could use

    Code:
    Sub PrintForms()
    
        Dim StartRow As Integer
        Dim EndRow As Integer
        Dim Msg As String
        Dim i As Integer
        Dim lngFrom As Long
        Dim lngTo As Long
        
        lngFrom = 6
        lngTo = 12
        
        Sheets("Resume").Activate
        StartRow = Range("StartRow")
        EndRow = Range("EndRow")
        
        If StartRow > EndRow Then
            Msg = "ERROR" & vbCrLf & "The starting row must be less than the ending row!"
            MsgBox Msg, vbCritical, APPNAME
        End If
        
        For i = StartRow To EndRow
            Range("RowIndex") = i
            If Range("Preview") Then
                ActiveSheet.PrintPreview
            Else
                ActiveSheet.PrintOut lngFrom, lngTo
                'But to make it more idiot proof, you could use the following
                'ActiveSheet.PrintOut Application.Min(Sheets.Count, lngFrom), Application.Min(Sheets.Count, lngTo)
            End If
        Next i
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. Macro To Print Selected Range
    By ciapul12 in forum Excel Help
    Replies: 3
    Last Post: 11-15-2013, 11:23 PM
  2. Replies: 14
    Last Post: 05-25-2013, 06:55 AM
  3. Macro To Delete Numbers With Trailing Character
    By Howardc in forum Excel Help
    Replies: 8
    Last Post: 04-05-2013, 08:14 PM
  4. Print VBA cancel command not working
    By Tony in forum Excel Help
    Replies: 1
    Last Post: 02-07-2013, 07:09 PM
  5. Replies: 0
    Last Post: 03-06-2012, 03:55 AM

Posting Permissions

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