VBA programme to download from url

Simon123456789

New Member
Joined
May 13, 2021
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Require VBA to download information from URL.

Where I have to key-in 3 information to obtain required information.

Require information for 24 years 1997 to 2021. Require a VBA where has to key in just once to get information for 24 years.

Thanking in Advance.



 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Require VBA to download information from URL.

Where I have to key-in 3 information to obtain required information.

Require information for 24 years 1997 to 2021. Require a VBA where has to key in just once to get information for 24 years.

used the following VBA but it shows error as Run time error 91 (object variable or with block variable not set).

VBA Code:
Public Sub Comets3()

    Dim cometCells As Range, cometCell As Range
    Dim inputDate As String, startDate As Date
    
    inputDate = InputBox("Enter start date")
    If inputDate = "" Then Exit Sub
    startDate = CDate(inputDate)
    
    With ActiveSheet
        Set cometCells = .Range("A2", .Cells(.Rows.Count, "A").End(xlUp))
    End With
    
    For Each cometCell In cometCells
        Application.StatusBar = cometCell.Value
        Get_Latest_Details "https://in-the-sky.org/ephemeris.php?startday=" & Day(startDate) & "&startmonth=" & Month(startDate) & "&startyear=" & Year(startDate) & _
                           "&ird=1&irs=1&ima=1&iph=0&ias=0&iss=0&iob=1&interval=0&tz=0&format=csv&objtype=3&objpl=" & Escape(cometCell.Value) & "&objtxt=" & Escape(cometCell.Value), _
                           cometCell.Offset(0, 1)
        DoEvents
    Next
    
    Application.StatusBar = ""

    MsgBox "Finished"

End Sub


Private Sub Get_Latest_Details(URL As String, destinationCell As Range)

    Static httpReq As Object
    Dim HTMLdoc As Object
    Dim table As Object, dataRow As Object
    Dim i As Long
    
    If httpReq Is Nothing Then Set httpReq = CreateObject("MSXML2.XMLHTTP")
    
    With httpReq
        .Open "GET", URL, False
        .send
        If .Status = 200 Then
            Set HTMLdoc = CreateObject("HTMLfile")
            HTMLdoc.Open
            HTMLdoc.write .responseText
            HTMLdoc.Close
            
            Set table = HTMLdoc.getElementsByTagName("TABLE")(1)
            Set dataRow = table.Rows(3)
            For i = 0 To dataRow.Cells.Length - 1
                destinationCell.Offset(0, i).Value = dataRow.Cells(i).innerText
            Next
            Set HTMLdoc = Nothing
        Else
            destinationCell.Offset(0, 0).Value = "Error"
            destinationCell.Offset(0, 1).Value = URL
            destinationCell.Offset(0, 2).Value = .statusText
        End If
    End With
    
End Sub


Private Function Escape(ByVal param As String) As String

    Dim i As Integer, BadChars As String

    BadChars = "%<>=&!@#$^()+{[}]|\;:'"",/?"
    For i = 1 To Len(BadChars)
        param = Replace(param, Mid(BadChars, i, 1), "%" & Hex(Asc(Mid(BadChars, i, 1))))
    Next
    param = Replace(param, " ", "+")
    Escape = param

End Function

Is it possible to rectify the problem and modify to use for the 3 URLs stated below?

Thanking in Advance.

Pratipada 1998 | Pratipada Tithi in 1998

1998 Pratipada tithi dates. Krishna & Shukla paksha Pratipada in 1998, next Pratipada date with exact start and end time.
www.prokerala.com

Hindu Calendar 2007, November

Hindu calendar November 2007 with festivals & daily panchang. Holidays, daily tithi, vrat, Hindu festival calendar November 2007.
www.prokerala.com

Nakshatra - Nakshatras, Janma Nakshatra and Astrology

Find your Nakshatra. This Nakshatra Calculator helps you find your Janma Nakshatras. There are 27 nakshatras and nakshatra is an important aspect of Indian astrology
www.astroica.com
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Novice to VBA. Require Help - OzGrid Free Excel/VBA Help Forum
and Novice to VBA. Require Help

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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