Необходимо загружать новости с нескольких веб-сайтов в Excel на основе введенных дат, которые пользователь предоставит в VBA.
Существует несколько веб-сайтов, которые должны получать новости в соответствии с диапазоном дат по одному в Excel.
Пример веб-сайта: https://about.att.com/allnews.html.
Попробовал ниже код, но получил ошибку и не написал код для даты ввода ниже
Option Explicit
Const sSiteName = "https://about.att.com/allnews.html"
Private Sub GetHTMLContents()
' Create Internet Explorer object.
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True ' Keep this hidden.
IE.Navigate sSiteName
' Wait till IE is fully loaded.
While IE.ReadyState <> 4
DoEvents
Wend
Dim oHDoc As HTMLDocument ' Create document object.
Set oHDoc = IE.Document
Dim oHEle As HTMLUListElement ' Create HTML element (<ul>) object.
Set oHEle = oHDoc.getElementById("ulPost") ' Get the element reference using its ID.
Dim iCnt As Integer
' Loop through elements inside the <ul> element and find <h2>, which has the texts we want.
With oHEle
For iCnt = 0 To .getElementsByTagName("h2").Length - 1
Debug.Print .getElementsByTagName("h2").Item(iCnt).getElementsByTagName("a").Item(0).innerHTML
Next iCnt
End With
' Clean up.
IE.Quit
Set IE = Nothing
Set oHEle = Nothing
Set oHDoc = Nothing
End Sub