Sub out of range

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I don't understand why I get "Subcription out of range" error msg when I
want to set a range (myrng)
Here's my VBA Macro:
Dim fName As String
fName = Application.GetOpenFilename()
Workbooks.Open filename:=fName
Set myrng = Workbooks(fName).Worksheets("Invoices").Range("a1:b13")
Thanks
 
I suspect it's because GetOpenFilename returns to fName a path as well
as the file name.


Try:

Dim fName As Variant
Dim myrng As Range
fName = Application.GetOpenFilename
If fName = False Then Exit Sub 'User cancelled
Workbooks.Open Filename:=fName
Set myrng = ActiveWorkbook.Worksheets("Invoices").Range("A1:B13")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Out of Range 5
Activating Workbooks 2
Open files from List 9
Saving and Sharing with VBA 1
VBA Formula Help 6
Allowing user to choose to accept saveas option 4
Worksheet.activate 1
Listbox in VBA 1

Back
Top