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
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