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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

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