Runtime Error 9 "Subscript is out of range" Occurs only on Certain Computers

excelquestions12

New Member
Joined
Dec 5, 2013
Messages
3
Hello,

I have some VBA code that downloads a file from the web to the current user's Documents folder, opens it, and filters and copies some data. When I run this on my computer, I have no issue, however, when my co-worker runs the Macro he gets an error at the line in red below. The file has opened successfully and worksheet/workbook names look correct. I've seen several posts on different forums about this, but none of the solutions I have seen work for my situation.

Thanks in advance for the help!

Code:

Sub get_info()

Dim copy_range As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'download the file
Download_File "http://filedownloadlocation.com", "C:\Users\" & Environ("username") & "\Documents\myworkbook.xlsx"

'open the file
Workbooks.Open Filename:="C:\Users\" & Environ("USERNAME") & "\Documents\myworkbook.xlsx"

'filter & copy/paste the data
Workbooks(myworkbook).Worksheets(mysheet).AutoFilterMode = False
Workbooks(myworkbook).Worksheets(mysheet).Range("A3").AutoFilter Field:=13, Criteria1:="Y"
Set copy_range = Workbooks(myworkbook).Worksheets(mysheet).Range("A:N")

.
.
.

End Sub


Function Download_File(ByVal vWebFile As String, ByVal vLocalFile As String) As Boolean
Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte

'You can also set a ref. to Microsoft XML, and Dim oXMLHTTP as MSXML2.XMLHTTP
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the website
oXMLHTTP.Send 'send request

'Wait for request to finish
Do While oXMLHTTP.readyState <> 4
DoEvents
Loop

oResp = oXMLHTTP.responseBody 'Returns the results as a byte array

'Create local file and save results to it
vFF = FreeFile
If Dir(vLocalFile) <> "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF

'Clear memory
Set oXMLHTTP = Nothing
End Function
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
It doesn't appear that the variables myworkbook and mysheet have been given any values.
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,229
Members
453,152
Latest member
ChrisMd

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