data01.htmlファイルのタグ例 |
<BODY> <font size=4 color=#ff00ff><b> テキストボックス</b></font> <hr> <FORM NAME="Myfn"> テキストボックスの元文字:<br> テストaAbBaAbBあい123123<br> <INPUT TYPE="text" NAME="txt" SIZE=47 MAXLENGTH=30 Value="テストaAbBaAbBあい123123"> <br><br> </BODY> |
Dim myobj As Object, objIE As Object Dim fff As String, mycnt Dim sanp As Integer Sub data1() fff = ThisWorkbook.Path & "\data01.html" sanp = 1 Call datam End Sub -------------------------------------------------------- Sub datam() Set myobj = CreateObject("Shell.Application") mycnt = myobj.Windows.Count With myobj.Windows Shell ("EXPLORER.EXE " & fff) Do DoEvents Loop Until mycnt + 1 <= .Count Set objIE = .Item(mycnt) End With Do While objIE.ReadyState <> 4 Or objIE.Busy = True DoEvents Loop Select Case sanp Case 1 Call data1a Case 2 Call data2a End Select Set objIE = Nothing Set myobj = Nothing End Sub --------------------------------------------------------- Sub data1a() Dim myhtml As String myhtml = objIE.Document.Body.innerHTML objIE.Quit MsgBox myhtml End Sub |
Sub data2a() Dim myhtml As String myhtml = objIE.Document.Body.innerText objIE.Quit MsgBox myhtml End Sub |
data02.htmlファイルのタグ例 |
<BODY> TABLE ID="id33a" を指定。<br> <TABLE BORDER=1 ID="id3a"> <TR id="id3b"><TD>A1セル </TD><TD>A2セル </TD><TD>A3セル </TD></TR> <TR><TD>B1セル </TD><TD>B2セル </TD><TD id="id3c">B3セル </TD></TR> <TR><TD>C1セル </TD><TD>C2セル </TD><TD>C3セル </TD></TR> </TABLE> </BODY> |
Sub data3_1a() Dim mydat As String mydat = objIE.Document.getElementById("id3a").innerHTML objIE.Quit MsgBox "(指定したエレメントIDのデータ)" & Chr(10) & Chr(10) & mydat End Sub |
Sub data3_2a() Dim mydat As String mydat = objIE.Document.getElementById("id3b").innerHTML objIE.Quit MsgBox "(指定したエレメントIDのデータ)" & Chr(10) & Chr(10) & mydat End Sub |
Sub data3_3a() Dim mydat As String mydat = objIE.Document.getElementById("id3c").innerHTML objIE.Quit MsgBox "(指定したエレメントIDのデータ)" & Chr(10) & Chr(10) & mydat End Sub |
Sub data3_4a() Dim mydat As String, objTable As Object Set objTable = objIE.Document.all("id3a") mydat = objTable.Rows(2).Cells(1).innerText objIE.Quit MsgBox "(指定したRows(2).Cells(1)データ)" & Chr(10) & Chr(10) & mydat End Sub |
Sub data4a() objIE.Document.Links(3).Click End Sub |
If objIE.Document.Links(3).innerHTML = "KIの写真展示室" Then objIE.Document.Links(3).Click End If |
Sub data5_1a() cnt = 1 Cells(cnt, 1).Value = "(1)「outerHTML」で取得": cnt = cnt + 1 For i = 0 To objIE.Document.Links.Length - 1 Cells(cnt, 1) = "'" & objIE.Document.Links(i).outerHTML cnt = cnt + 1 Next i objIE.Quit End Sub |
Sub data5_2a() cnt = 7 Cells(cnt, 1).Value = "(2)「innerHTML」で取得": cnt = cnt + 1 For i = 0 To objIE.Document.Links.Length - 1 Cells(cnt, 1) = "'" & objIE.Document.Links(i).innerHTML cnt = cnt + 1 Next i objIE.Quit End Sub |
Sub data5_3a() cnt = 13 Cells(cnt, 1).Value = "(3)「href」で取得": cnt = cnt + 1 For i = 0 To objIE.Document.Links.Length - 1 Cells(cnt, 1) = "'" & objIE.Document.Links(i).href cnt = cnt + 1 Next i objIE.Quit End Sub |
Sub data5_4a() cnt = 19 Cells(cnt, 1).Value = "(4)「outerText」で取得": cnt = cnt + 1 For i = 0 To objIE.Document.Links.Length - 1 Cells(cnt, 1) = "'" & objIE.Document.Links(i).outerText cnt = cnt + 1 Next i objIE.Quit End Sub |
Sub data5_5a() cnt = 25 Cells(cnt, 1).Value = "(5)「innerText」で取得": cnt = cnt + 1 For i = 0 To objIE.Document.Links.Length - 1 Cells(cnt, 1) = "'" & objIE.Document.Links(i).innerText cnt = cnt + 1 Next i objIE.Quit End Sub |
Sub http1() Dim fff As String, oHttp As Object, dathaml As String fff = ThisWorkbook.Path & "\data01.html" Set oHttp = CreateObject("Microsoft.XMLHTTP") oHttp.Open "GET", fff, False oHttp.Send dathaml = StrConv(oHttp.responseBody, 64) MsgBox dathaml Set oHttp = Nothing End Sub |
Sub http2() Dim fff As String, oHttp As Object, dthtml As String Dim stchk As Integer, enchk As Integer, itmsu As Integer Dim r As Integer, c As Integer, j As Integer fff = ThisWorkbook.Path & "\data02.html" Set oHttp = CreateObject("Microsoft.XMLHTTP") oHttp.Open "GET", fff, False oHttp.Send dthtml = StrConv(oHttp.responseBody, 64) With CreateObject("VBScript.RegExp") .Pattern = ">([^<>]+)<" .Global = True On Error Resume Next stchk = InStr(1, dthtml, " |
Sub webQu1() Dim fff As String fff = ThisWorkbook.Path & "\data05.html" With ActiveSheet.QueryTables.Add(Connection:= _ "URL;" & fff, Destination:=Range("A1")) .RefreshStyle = xlOverwriteCells .WebTables = "2" .WebFormatting = xlWebFormattingNone .Refresh BackgroundQuery:=False End With End Sub |