- Katılım
- 29 Ocak 2024
- Mesajlar
- 201
- Excel Vers. ve Dili
- Office 2016
Merhabalar,
Aşağıdaki kodda;
For Each htmlTablo In htmlTablolar
.....................
Next htmlTablo
yerine Tablonun id' si (cr1) veya class name ("genTbl closedTbl crossRatesTbl elpTbl elp25") belirtirek kodu nasıl düzenleyebiliriz?
yardımlarınız için şimdiden teşekkürler
iyi akşamlar.
Aşağıdaki kodda;
For Each htmlTablo In htmlTablolar
.....................
Next htmlTablo
yerine Tablonun id' si (cr1) veya class name ("genTbl closedTbl crossRatesTbl elpTbl elp25") belirtirek kodu nasıl düzenleyebiliriz?
yardımlarınız için şimdiden teşekkürler
iyi akşamlar.
Kod:
Sub SP_US_500()
On Error Resume Next
Dim SH As Worksheet
Dim zaman As Double
Dim r As Long
Dim c As Integer
Dim IE As New InternetExplorer
Dim doc As HTMLDocument
Dim htmlDOC As MSHTML.HTMLDocument
Dim htmlTablo As MSHTML.IHTMLElement
Dim htmlTablolar As MSHTML.IHTMLElementCollection
Dim htmlSatir As MSHTML.IHTMLElement
Dim htmlElaman As MSHTML.IHTMLElement
Application.DisplayAlerts = False
zaman = Timer
Set SH = Sheets("sp500")
SH.Cells.ClearContents
SH.Activate
With IE
.navigate "https://tr.investing.com/indices/investing.com-us-500-components"
End With
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Set htmlDOC = IE.document
Application.Wait (Now + TimeValue("00:00:01"))
r = 1: c = 1
Set htmlTablolar = htmlDOC.getElementsByTagName("table")
For Each htmlTablo In htmlTablolar
For Each htmlSatir In htmlTablo.getElementsByTagName("tr")
c = 1
For Each htmlElaman In htmlSatir.Children
SH.Cells(r, c) = htmlElaman.innerText
c = c + 1
Next htmlElaman
r = r + 1
Next htmlSatir
Next htmlTablo
SH.Range("A:Z").EntireColumn.AutoFit
40:
Application.DisplayAlerts = True
IE.Quit
Set SH = Nothing
Set htmlDOC = Nothing
ThisWorkbook.Save
MsgBox "işlem tamam.." & Chr(10) & Chr(10) & _
"İşlem süresi ; " & Format(Timer - zaman, "0.00") & " Saniye", vbInformation
End Sub