Compile error "Subscript out of range" in simple set statement

ibud00

New Member
Joined
Aug 15, 2015
Messages
4
I'm obviously missing a fundamental concept. I have reduced my problem down to a few lines of code, and still can't solve it.

Code:
Sub tstSbScrptRng()


    Dim wkBk As Workbook
    Dim sPath As String
    Dim sFile As String
    
    sPath = "C:\Users\ibud0\Documents\"
    sFile = "Garbage.xlsx"
    
    Set wkBk = Workbooks(sPath & sFile)
'   Last statement gets "Subscript out of range" compile error message
    
End Sub

I'm drowning - please help!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
If the workbook is open, you should be using:

Code:
Set wkBk = Workbooks(sFile)

If not, you need to open it:

Code:
Set wkBk = Workbooks.Open(sPath & sFile)
 
Upvote 0
If the workbook isn't already open then you need:

Code:
Set wkBk = Workbooks.Open(sPath & sFile)

If the workbook is already open then you need:

Code:
Set wkBk = Workbooks(sFile)

WBD
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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