Sub FetchFromWeb()
Const STB = " Web Import : ", _
URL = "http://efms.serp.telangana.gov.in/MEPMATG/View/Reports/BLTargetAchievementDisbursementReport.aspx", _
OPT = "ctl00$ContentPlaceHolder1$ddlFinancialYear=2016-2017&__EVENTTARGET=", _
TBL = "ctl00_ContentPlaceHolder1_gvBankLinkage", _
CFY = "ctl00_ContentPlaceHolder1_ddlFinancialYear"
Dim oDoc As Object, oReq As Object, oHlk As Hyperlink, oRng As Range, DCS$, USS As Boolean
Set oDoc = CreateObject("HTMLfile")
Set oRng = Cells(1)
For Each oReq In Worksheets: oReq.UsedRange.Clear: Next
With Application
.ScreenUpdating = False
DCS = .DecimalSeparator
If DCS <> "." Then .DecimalSeparator = ".": USS = .UseSystemSeparators: .UseSystemSeparators = False
.StatusBar = STB & ActiveSheet.Name
Set oReq = CreateObject("WinHttp.WinHttpRequest.5.1")
oReq.Open "POST", URL, False
oReq.setRequestHeader "DNT", "1"
oReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
On Error GoTo Fin
oReq.send OPT & Split(OPT, "=")(0)
If oReq.Status = 200 Then
oDoc.body.innerHTML = oReq.responseText
If oDoc.frames.clipboardData.setData("Text", oDoc.all(TBL).outerHTML) Then
ActiveSheet.Paste oRng
oRng.Value = oDoc.all(CFY).Value
With ActiveSheet.UsedRange.Columns(1): .WrapText = False: .AutoFit: End With
End If
End If
For Each oHlk In ActiveSheet.Hyperlinks
.StatusBar = STB & oHlk.Range.Value
oReq.Open "POST", URL, False
oReq.setRequestHeader "DNT", "1"
oReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oReq.send OPT & Split(oHlk.Address, "'")(1)
oHlk.Address = ""
If oReq.Status = 200 Then
If Evaluate("ISREF('" & oHlk.Range.Value & "'!A1)") = False Then _
Worksheets.Add(, Worksheets(Worksheets.Count)).Name = oHlk.Range.Value
oHlk.SubAddress = "'" & oHlk.Range.Value & "'!A1"
oDoc.body.innerHTML = oReq.responseText
If oDoc.frames.clipboardData.setData("Text", oDoc.all(TBL).outerHTML) Then
With Worksheets(oHlk.Range.Value)
.Paste .Cells(1)
.Cells(1).Value = oDoc.all(CFY).Value
With .UsedRange.Columns(1): .WrapText = False: .AutoFit: End With
End With
End If
End If
Next
Fin:
If Err.Number Then Beep
oDoc.frames.clipboardData.clearData "Text"
If DCS <> "." Then .DecimalSeparator = DCS: .UseSystemSeparators = USS
.StatusBar = False
.Goto oRng, True
.ScreenUpdating = True
End With
Set oDoc = Nothing: Set oReq = Nothing: Set oRng = Nothing
End Sub