Printing a Sheet - Subscript Out of Range

jmabel01

New Member
Joined
Jan 24, 2011
Messages
10
All,

When I run this, assuming quarterNumber = 1, I get an error 9: subscript out of range.

Code:
Public Sub PrintAllAreas()

    Dim quarterNumber As String
    Dim strFile As String
    
    quarterNumber = QuarterToPrintForm.QuarterBox.Text
    
    Const strPath = "Omitted"
    
    Application.ScreenUpdating = False
    
    strFile = Dir(strPath & "*.xls")
    Do While Not strFile = ""
    With Workbooks.Open(Filename:=strPath & strFile, AddToMRU:=False)
       [COLOR=#ff0000][B] .Sheets("Sheet" & quarterNumber).PrintOut[/B][/COLOR]
        .Close SaveChanges:=False
    End With
    
    strFile = Dir
    Loop
    
    Application.ScreenUpdating = True
    
End Sub

The quarterNumber value does equal whatever I enter in the text box. I've been tinkering around with this error for over an hour and it still hasn't dawned on me yet.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I figured it out, apparently it wasn't referring to the sheet name but rather what was being displayed on the tab "Q1", "Q2", etc. This thread can be closed.
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,495
Members
449,088
Latest member
Melvetica

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top