Hi all.
INPUT TICKERS AND DATE...
OUT PUT OF MACRO
DESIRED OUT PUT
Can anyone help me to get the desired output using the above macro
Thanks
Code:
Public Sub downloadNse()
Dim arrURL() As String
Dim dtmDate As Date
Dim c As Range
Dim i As Long
Dim s As String
Dim bArray() As Byte
Dim hFile As Integer
Dim strLocalFile As String
Dim oXMLHTTP As MSXML2.XMLHTTP '(reference to C:\Windows\System32\msxml2.dll for 32 bit systems)
'-------------------------------------------------------------------------------
'ENTER CONSTANTS HERE - NOTHING ELSE *SHOULD* NEED TO BE CHANGED
Const CELL_WITH_DATE As String = "B2"
Const RANGE_WITH_SYMBOLS As String = "A2:A11"
Const SAVE_DIRECTORY As String = "C:\Macros\NSEIndices\" 'end with forward slash
'-------------------------------------------------------------------------------
dtmDate = Range(CELL_WITH_DATE).Value '//Date
strLocalFile = SAVE_DIRECTORY & Format(dtmDate, "YYYYMMDD") & ".csv"
For Each c In Range(RANGE_WITH_SYMBOLS) '//11 cells with symbols
If Len(c.Value) > 0 Then
ReDim Preserve arrURL(0 To i)
arrURL(i) = "http://www.nseindia.com/content/indices/histdata/"
arrURL(i) = arrURL(i) & UCase(c.Value)
arrURL(i) = arrURL(i) & Format(dtmDate, "dd-mm-yyyy") & "-" & Format(dtmDate, "dd-mm-yyyy") & ".csv"
i = i + 1
End If
Next c
'download the file from the web to the hardrive
'loop through symbols in turn
Set oXMLHTTP = New XMLHTTP
hFile = FreeFile
Open strLocalFile For Binary As #hFile
For i = 0 To UBound(arrURL)
oXMLHTTP.Open "GET", arrURL(i), False
oXMLHTTP.send
'Wait for request to finish
Do While oXMLHTTP.readyState <> 4
DoEvents
Loop
bArray = oXMLHTTP.responseBody
Put #hFile, , bArray
Next i
Handler:
On Error Resume Next
Close #hFile
Set oXMLHTTP = Nothing
End Sub
HTML:
[RANGE=cls:xl2bb-100][XR][XH=cs:8]Excel Workbook[/XH][/XR][XR][XH][/XH][XH]A[/XH][XH]B[/XH][XH]C[/XH][XH]D[/XH][XH]E[/XH][XH]F[/XH][XH]G[/XH][/XR][XR][XH]1[/XH][XD=h:l]BANK NIFTY[/XD][XD=h:r]20110411[/XD][XD=h:r]11591.00[/XD][XD=h:r]11637.00[/XD][XD=h:r]11551.75[/XD][XD=h:r]11597.80[/XD][XD=h:r]12854286.00[/XD][/XR][XR][XH]2[/XH][XD=h:l]CNX 100[/XD][XD=h:r]20110411[/XD][XD=h:r]5708.65[/XD][XD=h:r]5726.65[/XD][XD=h:r]5677.70[/XD][XD=h:r]5684.10[/XD][XD=h:r]153565031.00[/XD][/XR][XR][XH]3[/XH][XD=h:l]CNX ENERGY[/XD][XD=h:r]20110411[/XD][XD=h:r]9273.55[/XD][XD=h:r]9292.65[/XD][XD=h:r]9177.50[/XD][XD=h:r]9188.20[/XD][XD=h:r]12952015.00[/XD][/XR][XR][XH]4[/XH][XD=h:l]CNX FMCG[/XD][XD=h:r]20110411[/XD][XD=h:r]9286.55[/XD][XD=h:r]9400.90[/XD][XD=h:r]9260.05[/XD][XD=h:r]9282.40[/XD][XD=h:r]17275345.00[/XD][/XR][XR][XH]5[/XH][XD=h:l]CNX INFRA[/XD][XD=h:r]20110411[/XD][XD=h:r]3130.15[/XD][XD=h:r]3150.60[/XD][XD=h:r]3103.45[/XD][XD=h:r]3108.70[/XD][XD=h:r]109671988.00[/XD][/XR][XR][XH]6[/XH][XD=h:l]CNX IT[/XD][XD=h:r]20110411[/XD][XD=h:r]7107.50[/XD][XD=h:r]7207.50[/XD][XD=h:r]7099.20[/XD][XD=h:r]7157.85[/XD][XD=h:r]11538782.00[/XD][/XR][XR][XH]7[/XH][XD=h:l]CNX MIDCAP[/XD][XD=h:r]20110411[/XD][XD=h:r]8287.65[/XD][XD=h:r]8290.80[/XD][XD=h:r]8213.90[/XD][XD=h:r]8229.95[/XD][XD=h:r]120585251.00[/XD][/XR][XR][XH]8[/XH][XD=h:l]CNX MNC[/XD][XD=h:r]20110411[/XD][XD=h:r]4815.65[/XD][XD=h:r]4822.35[/XD][XD=h:r]4761.50[/XD][XD=h:r]4769.15[/XD][XD=h:r]8992613.00[/XD][/XR][XR][XH]9[/XH][XD=h:l]CNX NIFTY JUNIOR[/XD][XD=h:r]20110411[/XD][XD=h:r]11533.70[/XD][XD=h:r]11533.70[/XD][XD=h:r]11419.85[/XD][XD=h:r]11437.50[/XD][XD=h:r]60830899.00[/XD][/XR][XR][XH]10[/XH][XD=h:l]CNX PHARMA[/XD][XD=h:r]20110411[/XD][XD=h:r]4608.25[/XD][XD=h:r]4618.25[/XD][XD=h:r]4575.35[/XD][XD=h:r]4588.20[/XD][XD=h:r]5284273.00[/XD][/XR][XR][XH=cs:8][RANGE][XR][XD]20110411[/XD][XH][/XH][/XR][/RANGE][/XH][/XR][/RANGE]
OUT PUT OF MACRO
HTML:
[RANGE=cls:xl2bb-100][XR][XH=cs:8]Excel Workbook[/XH][/XR][XR][XH][/XH][XH]A[/XH][XH]B[/XH][XH]C[/XH][XH]D[/XH][XH]E[/XH][XH]F[/XH][XH]G[/XH][/XR][XR][XH]1[/XH][XD=h:l]Date[/XD][XD=h:l]Open[/XD][XD=h:l]High[/XD][XD=h:l]Low[/XD][XD=h:l]Close[/XD][XD=h:l]Shares Traded[/XD][XD=h:l]Turnover (Rs. Cr)[/XD][/XR][XR][XH]2[/XH][XD=h:r]11-Apr-11[/XD][XD=h:r]11591[/XD][XD=h:r]11637[/XD][XD=h:r]11551.75[/XD][XD=h:r]11597.8[/XD][XD=h:r]12854286[/XD][XD=h:r]1390.66[/XD][/XR][XR][XH]3[/XH][XD=h:l]Date[/XD][XD=h:l]Open[/XD][XD=h:l]High[/XD][XD=h:l]Low[/XD][XD=h:l]Close[/XD][XD=h:l]Shares Traded[/XD][XD=h:l]Turnover (Rs. Cr)[/XD][/XR][XR][XH]4[/XH][XD=h:r]11-Apr-11[/XD][XD=h:r]5708.65[/XD][XD=h:r]5726.65[/XD][XD=h:r]5677.7[/XD][XD=h:r]5684.1[/XD][XD=h:r]153565031[/XD][XD=h:r]5944.65[/XD][/XR][XR][XH]5[/XH][XD=h:l]Date[/XD][XD=h:l]Open[/XD][XD=h:l]High[/XD][XD=h:l]Low[/XD][XD=h:l]Close[/XD][XD=h:l]Shares Traded[/XD][XD=h:l]Turnover (Rs. Cr)[/XD][/XR][XR][XH]6[/XH][XD=h:r]11-Apr-11[/XD][XD=h:r]9273.55[/XD][XD=h:r]9292.65[/XD][XD=h:r]9177.5[/XD][XD=h:r]9188.2[/XD][XD=h:r]12952015[/XD][XD=h:r]556.23[/XD][/XR][XR][XH]7[/XH][XD=h:l]Date[/XD][XD=h:l]Open[/XD][XD=h:l]High[/XD][XD=h:l]Low[/XD][XD=h:l]Close[/XD][XD=h:l]Shares Traded[/XD][XD=h:l]Turnover (Rs. Cr)[/XD][/XR][XR][XH]8[/XH][XD=h:r]11-Apr-11[/XD][XD=h:r]9286.55[/XD][XD=h:r]9400.9[/XD][XD=h:r]9260.05[/XD][XD=h:r]9282.4[/XD][XD=h:r]17275345[/XD][XD=h:r]330.87[/XD][/XR][XR][XH]9[/XH][XD=h:l]Date[/XD][XD=h:l]Open[/XD][XD=h:l]High[/XD][XD=h:l]Low[/XD][XD=h:l]Close[/XD][XD=h:l]Shares Traded[/XD][XD=h:l]Turnover (Rs. Cr)[/XD][/XR][XR][XH]10[/XH][XD=h:r]11-Apr-11[/XD][XD=h:r]3130.15[/XD][XD=h:r]3150.6[/XD][XD=h:r]3103.45[/XD][XD=h:r]3108.7[/XD][XD=h:r]109671988[/XD][XD=h:r]1368.55[/XD][/XR][XR][XH]11[/XH][XD=h:l]Date[/XD][XD=h:l]Open[/XD][XD=h:l]High[/XD][XD=h:l]Low[/XD][XD=h:l]Close[/XD][XD=h:l]Shares Traded[/XD][XD=h:l]Turnover (Rs. Cr)[/XD][/XR][XR][XH]12[/XH][XD=h:r]11-Apr-11[/XD][XD=h:r]7107.5[/XD][XD=h:r]7207.5[/XD][XD=h:r]7099.2[/XD][XD=h:r]7157.85[/XD][XD=h:r]11538782[/XD][XD=h:r]731.11[/XD][/XR][XR][XH]13[/XH][XD=h:l]Date[/XD][XD=h:l]Open[/XD][XD=h:l]High[/XD][XD=h:l]Low[/XD][XD=h:l]Close[/XD][XD=h:l]Shares Traded[/XD][XD=h:l]Turnover (Rs. Cr)[/XD][/XR][XR][XH]14[/XH][XD=h:r]11-Apr-11[/XD][XD=h:r]8287.65[/XD][XD=h:r]8290.8[/XD][XD=h:r]8213.9[/XD][XD=h:r]8229.95[/XD][XD=h:r]120585251[/XD][XD=h:r]1580.28[/XD][/XR][XR][XH]15[/XH][XD=h:l]Date[/XD][XD=h:l]Open[/XD][XD=h:l]High[/XD][XD=h:l]Low[/XD][XD=h:l]Close[/XD][XD=h:l]Shares Traded[/XD][XD=h:l]Turnover (Rs. Cr)[/XD][/XR][XR][XH]16[/XH][XD=h:r]11-Apr-11[/XD][XD=h:r]4815.65[/XD][XD=h:r]4822.35[/XD][XD=h:r]4761.5[/XD][XD=h:r]4769.15[/XD][XD=h:r]8992613[/XD][XD=h:r]342.89[/XD][/XR][XR][XH]17[/XH][XD=h:l]Date[/XD][XD=h:l]Open[/XD][XD=h:l]High[/XD][XD=h:l]Low[/XD][XD=h:l]Close[/XD][XD=h:l]Shares Traded[/XD][XD=h:l]Turnover (Rs. Cr)[/XD][/XR][XR][XH]18[/XH][XD=h:r]11-Apr-11[/XD][XD=h:r]11533.7[/XD][XD=h:r]11533.7[/XD][XD=h:r]11419.85[/XD][XD=h:r]11437.5[/XD][XD=h:r]60830899[/XD][XD=h:r]1308.26[/XD][/XR][XR][XH]19[/XH][XD=h:l]Date[/XD][XD=h:l]Open[/XD][XD=h:l]High[/XD][XD=h:l]Low[/XD][XD=h:l]Close[/XD][XD=h:l]Shares Traded[/XD][XD=h:l]Turnover (Rs. Cr)[/XD][/XR][XR][XH]20[/XH][XD=h:r]11-Apr-11[/XD][XD=h:r]4608.25[/XD][XD=h:r]4618.25[/XD][XD=h:r]4575.35[/XD][XD=h:r]4588.2[/XD][XD=h:r]5284273[/XD][XD=h:r]246.91[/XD][/XR][XR][XH=cs:8][RANGE][XR][XD]20110411[/XD][XH][/XH][/XR][/RANGE][/XH][/XR][/RANGE]
DESIRED OUT PUT
HTML:
[RANGE=cls:xl2bb-100][XR][XH=cs:3]Excel Workbook[/XH][/XR][XR][XH][/XH][XH]A[/XH][XH]B[/XH][/XR][XR][XH]1[/XH][XD=h:c|fw:b]TICKERS[/XD][XD=h:c|fw:b]DATE[/XD][/XR][XR][XH]2[/XH][XD=h:l]BANK NIFTY[/XD][XD=h:r]11/04/2011[/XD][/XR][XR][XH]3[/XH][XD=h:l]CNX 100[/XD][XD][/XD][/XR][XR][XH]4[/XH][XD=h:l]CNX ENERGY[/XD][XD][/XD][/XR][XR][XH]5[/XH][XD=h:l]CNX FMCG[/XD][XD][/XD][/XR][XR][XH]6[/XH][XD=h:l]CNX INFRA[/XD][XD][/XD][/XR][XR][XH]7[/XH][XD=h:l]CNX IT[/XD][XD][/XD][/XR][XR][XH]8[/XH][XD=h:l]CNX MIDCAP[/XD][XD][/XD][/XR][XR][XH]9[/XH][XD=h:l]CNX MNC[/XD][XD][/XD][/XR][XR][XH]10[/XH][XD=h:l]CNX NIFTY JUNIOR[/XD][XD][/XD][/XR][XR][XH]11[/XH][XD=h:l]CNX PHARMA[/XD][XD][/XD][/XR][XR][XH=cs:3][RANGE][XR][XD]Sheet1[/XD][XH][/XH][/XR][/RANGE][/XH][/XR][/RANGE]
Can anyone help me to get the desired output using the above macro
Thanks
Last edited: