VBA - Doesn't copy from one workbook to other and active window not working

BeginnerAtWork

New Member
Joined
Aug 9, 2013
Messages
4
Hi forum members,

I have been at this macro for hours and unable to find out why it wont work, and from testing various available scripts on the internet this seems to be the fastest.

Objective - To download and open a file from a website i.e. http://www.asx.com.au/asx/research/ASXListedCompanies.csv
and on my current workbook "lets say Analysis.xlsx" worksheet "Summary" I am trying to open the downloaded file and copy information from ASXListedCompanies.csv into Summary then close ASXListedCompanies.csv and return back to the Summary worksheet. This is what I have, but it always opens the downloaded file and nothing is copied onto the Summary worksheet in the analysis workbook, please help!


Sub GetNewASXcompanies()
Dim myURL As String
myURL = "http://www.asx.com.au/asx/research/ASXListedCompanies.csv" 'direct http link


Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False
WinHttpReq.Send


myURL = WinHttpReq.ResponseBody
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.ResponseBody
Kill ("C:\TEMP\file.csv")
oStream.SaveToFile ("C:\TEMP\file.csv")
oStream.Close
End If
ssheet = "Summary"
bgsheet = ("C:\TEMP\file.csv")
Set wnd = ActiveWindow
Application.ScreenUpdating = False
Sheets(ssheet).Cells.ClearContents
Workbooks.Open filename:=bgsheet
Windows(sfile).Activate
ActiveSheet.Cells.Copy
wnd.Activate
Sheets(ssheet).Paste
Application.DisplayAlerts = False
Windows(bgsheet).Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,216,163
Messages
6,129,223
Members
449,495
Latest member
janzablox

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