Printing every worksheet beyond a specific worksheet automatically

WxShady13

Board Regular
Joined
Jul 24, 2018
Messages
77
I have a workbook that contains numerous worksheets. I want to be able to have a macro that will automatically print every worksheet beyond the specific one when a button is clicked. Is this possible?
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,735
Office Version
2007
Platform
Windows
Try this:


Code:
Sub Print_Every_Worksheet()
    'Printing every worksheet beyond a specific worksheet automatically
    '
    hoja = InputBox("Write the name a specific worksheet", "PRINT SHEETS")
    If hoja = "" Then Exit Sub
    '
    For Each h In Sheets
        If LCase(h.Name) = LCase(hoja) Then
            n = h.Index
            Exit For
        End If
    Next
    If n = 0 Then
        MsgBox "There is no sheet with the name : " & hoja
        Exit Sub
    End If
    '
    For i = n To Sheets.Count
        Sheets(i).PrintOut
    Next
    MsgBox "End"
End Sub
 

WxShady13

Board Regular
Joined
Jul 24, 2018
Messages
77
That works great, however it errors out after printing 14 worksheets. There are 4 more left to print out and are the same as the others. Any idea why it errors out after 14 and does not complete?
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,735
Office Version
2007
Platform
Windows
That works great, however it errors out after printing 14 worksheets. There are 4 more left to print out and are the same as the others. Any idea why it errors out after 14 and does not complete?

What error message do you send?
And in which line of the macro does it stop?



Put the following instruction at the beginning of the macro and try again

Code:
On Error Resume Next
 

WxShady13

Board Regular
Joined
Jul 24, 2018
Messages
77
Wow with that code I did not get an error at all!
 

Forum statistics

Threads
1,081,574
Messages
5,359,704
Members
400,545
Latest member
Damntheman30

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top