attached file contains entire project...
the code downloads zip file from website and extracts it... then it has to read the extracted file and output selected columns from the file to another file. its not doing that
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
Alias "DeleteUrlCacheEntryA" _
(ByVal lpszUrlName As String) As Long
Private Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
Private Sub Command1_Click()
On Error GoTo Err
Const q As String = "/"
Dim tmp As String, fname As String, pos As Long, fPath As String
Dim first As Date, last As Date, spath As String, d As Date
Dim oUnZip As CGUnzipFiles
cap = Me.Caption
If Dir(App.Path & "\NSE EQUITY\", vbDirectory) = "" Then
MkDir App.Path & "\NSE EQUITY\"
End If
spath = App.Path & "\NSE EQUITY\" ' folder to save files : note trailing \
first = MonthView1
last = MonthView2
'http://www.nseindia.com/content/historical/EQUITIES/2011/JAN/cm03JAN2011bhav.csv.zip
strurl = "http://www.nseindia.com/content/historical/EQUITIES/"
For d = first To last
sSourceURL = strurl & Year(d) & q & UCase(Format(d, "mmm")) & q & "cm" & UCase(Format(d, "ddmmmyyyy")) & "bhav.csv.zip"
Debug.Print sSourceURL
fname = Format(d, "dd-mm-yyyy") & ".zip"
slocalfile = spath & fname
Me.Caption = "Downloading " & fname
Call DeleteUrlCacheEntry(sSourceURL)
If URLDownloadToFile(0&, sSourceURL, slocalfile, BINDF_GETNEWESTVERSION, 0&) = S_OK Then
Set oUnZip = New CGUnzipFiles
With oUnZip
.ZipFileName = spath & fname
.ExtractDir = spath
.HonorDirectories = False
If .Unzip <> 0 Then
MsgBox .GetLastMessage
End If
End With
Set oUnZip = Nothing
' MsgBox fName & "Extracted Successfully to " & .ExtractDir
FileCopy spath & "cm" & UCase(Format(d, "ddmmmyyyy")) & "bhav.csv", spath & Format(d, "dd-mm-yyyy") & ".csv"
FileName = spath & Format(d, "dd-mm-yyyy") & ".csv"
Kill slocalfile
Kill spath & "cm" & UCase(Format(d, "ddmmmyyyy")) & "bhav.csv"
Debug.Print FileName
' sLastSymbol = "zzz" 'Set to something Symbol cannot possibly be initially.
Open App.Path & "\temp.csv" For Output As #2
Open App.Path & "\NSE EQUITY\" & FileName For Input As #1
Do While Not EOF(1)
Line Input #1, sLineIn
sCols = Split(sLineIn, ",")
sSymbol = sCols(0)
sDate = sCols(10)
sOpen = sCols(2)
sHigh = sCols(3)
sLow = sCols(4)
sClose = sCols(5)
sVolume = sCols(8)
Debug.Print sLineIn
sLineOut = sSymbol & "," & sDate & "," & sOpen & "," & sHigh & "," & sLow & "," & sClose & "," & sVolume
Print #2, sLineOut
Loop
Close #1
Close #2
' Delete file 1 and rename file 2 as the original file 1 name.
' // Delete the original file
'Kill slocalfile
' // Rename the temp file to the original name
' Name App.Path & "\temp.csv" As slocalfile
End If
Next
Me.Caption = cap
'YOU CAN TAKE THIS BELOW OUT IF U DONT WANT IT
MsgBox "Saved to " & spath, vbInformation + vbOKOnly, "Success!"
Exit Sub
Err: MsgBox "Error", vbCritical + vbOKOnly, "Market Was Closed"
End Sub