Sub GoToWebSiteAndPlayAroundNew()
Dim appie As Object 'InternetExplorer.Application Dim URL As String Dim i As Long, strText As String
Dim doc As Object, hTable As Object, hBody As Object , hTR As Object, HTD As Object Dim tb As Object, bb As Object, tr As Object, td As Object
Dim y As Long, z As Long, wb Als Excel.Workbook, ws Als Excel.Worksheet
Dim sws Wie SHDocVw.ShellWindows Dim IE As Object
Dim ViE Als SHDocVw.InternetExplorer
Set wb = Excel.ActiveWorkbook Set ws = wb.ActiveSheet
Set Appie = Create (“ InternetExplorer.Application ") URL =" http://dgft.delhi.nic.in:8100/dgft/IecPrint "
y = 1 'Spalte A in Excel z = 1' Row 1 in Excel
Mit Appie .navigate URL .Visible = True
Do While .BUSY: DoEvents: Loop Do While .ReadyState <> 4: DoEvents: Loop
.document.getElementById ("IEC") .Value = "0495024988"
.document.getElementById ("name"). Value = "AMB"
End With
On Error Resume Next
Mit appIE.document
Set elems = .getElementsByTagName ("input") für jede E In elems
Wenn (z.getAttribute ("value") = "Submit Query") Dann e.Click Exit For End If
Weiter e
End With Set sws = Neue SHDocVw.ShellWindows For Each ViE In sws 'Wenn Left (vIE.LocationURL, 4) = "http" Then' vermeiden Explorer-Fenster/etc diese Weise 'If MsgBox ("IE-Fenster gefunden Die URL lautet:". & vbCrLf & vIE.LocationURL & vbCrLf & _ ' vbCrLf & "Willst du den htm sehen? l? "vbYesNo) = vbYes Dann 'Show html in einem msgbox ' MsgBox vIE.document.body.innerHTML dim VFF so lange 'vff = Free ' öffnen 'oder in eine Datei setzen'" C : \ thehtml.txt“für die Ausgabe als #vff '# vff Druck, vie.document.body.innerhtml 'schließen #vff ' End If ' End If
Set doc = vIE.document
Set hTable = doc.getElementsByTagName("table")
For Each tb In hTable
Set hBody = tb.getElementsByTagName("tbody")
For Each bb In hBody
Set hTR = bb.getElementsByTagName("tr")
MsgBox hTR.Length
For Each tr In hTR
Set hTD = tr.getElementsByTagName("td")
MsgBox hTD.Length
y = 1 ' Resets back to column A
For Each td In hTD
ws.Cells(z, y).Value = td.innerText
y = y + 1
Next td
DoEvents
z = z + 1
Next tr
Exit For
Next bb
Exit For
Weiter tb
Weiter
End Sub
Die Hauptfrage ist, wie erhalten Sie Zugriff auf das HTML von Excel VBA. Bitte zeigen Sie, wie Sie das tun. Wenn Sie beispielsweise Zugriff auf das DOM in einem Browser haben, unterscheiden sich die weiteren Methoden nicht wesentlich zwischen JavaScript und VBA. –
Hallo Alex, der Code, den ich verwendet habe, ist unten eingefügt. –