HTML ソース コード (約 1,000,000 文字) からの大きな文字列があります。msinet.ocx を使用して、適切な Web サイトからテキストを表示しています。別のキー フレーズ (「コンポーネント アクセサリ マトリックス」) の直前にあるキー フレーズ (「pkid=」) を見つけるために、小さなコード セグメントを作成しましたが、正しく動作しません。これが私が今持っているものです:
workbench = Cells(columnNumber, 1).Value
myURL = "http://beams.us.yazaki.com/Beams/ViewDetails.aspx?topic=document&pkid=" _
& workbench
Dim inet1 As Inet
Dim mypage As String
Set inet1 = New Inet
With inet1
.Protocol = icHTTP
.URL = myURL
mypage = .OpenURL(.URL, icString)
End With
CAMnum = InStr(mypage, "Component Accessory Matrix")
intStart = InStrRev(mypage, "pkid=", CAMnum) + 5
newnum = Mid(mypage, intStart, 6)
Cells(columnNumber, 2).Value = newnum
問題はmypage = .OpenURL(.URL, icString)
;にあるようです。を実行するlen(mypage)
と、約 100,000 の値が返されますが、約 100 万の値が返されるはずです。誰かがこれを説明できますか?
編集:Gimp、私はあなたの解決策を試しましたが、何らかの理由で ReturnStr はまだ空です。2048 の代わりに 1024 も試しましたが、何も変わりませんでした。これまでのコードをコピーして貼り付けました。
Dim myURL
ActiveSheet.Range("a1").End(xlDown).Select lastColumn = Selection.Row
columnNumber = 2 の場合 lastColumn workbench = Cells(columnNumber, 1).Value myURL = "http://beams.us.yazaki.com/Beams/ViewDetails.aspx?topic=document&pkid=" _ & workbench Dim inet1 As Inet Dim mypage As String Dim ReturnStr As String
Set inet1 = New Inet
With inet1
.Protocol = icHTTP
.URL = myURL
mypage = .OpenURL(.URL, icString)
ReturnStr = .GetChunk(1024, icString)
End With
Do While Len(ReturnStr) <> 0
DoEvents
mypage = mypage & ReturnStr
ReturnStr = inet1.GetChunk(1024, icString)
Loop
CAMnum = InStr(mypage, "Component Accessory Matrix")
intStart = InStrRev(mypage, "pkid=", CAMnum) + 5
newnum = Mid(mypage, intStart, 6)
Cells(columnNumber, 2).Value = newnum
Next columnNumber
ここで何か不足していますか?オンラインで GetChunk 関数を検索しましたが、構文的に間違っているとは思いませんが、根本的なエラーである可能性があります。助けていただければ幸いです。