1

编辑

我正在尝试调用 inet1.GetChunk 以在一个变量名下呈现文档的整个 HTML。但是,我遇到了问题。我在下面发布了我的代码:

Sub File_Names()

Dim myURL

ActiveSheet.Range("a1").End(xlDown).Select
lastColumn = Selection.Row

For columnNumber = 2 To lastColumn
    workbench = Cells(columnNumber, 1).Value
    myURL = "my_web_page"&workbench
    Dim inet1 As Inet


Set inet1 = New Inet
With inet1
    .Protocol = icHTTP
    .URL = myURL
    .Execute , "Get"
End With

While inet1.StillExecuting
    DoEvents
Wend

mypage = inet1.GetChunk(1024, icString)


Do While Len(ReturnStr) <> 0
    DoEvents
    mypage = mypage & ReturnStr
    Cells(2, 10).Value = mypage
    ReturnStr = myURL.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


End Sub

我得到的问题是mypage = inet1.GetChunk(1024,icString)。它显示“运行时错误 24:需要对象”。我不确定为什么会收到此错误消息。有什么建议么?

4

1 回答 1

0

.OpenURL是同步的;它会打开 URL 然后阻塞,直到它完全加载到mypage变量中,所以内容已经“在一个变量名下”。

如果您想要异步读取,则需要使用.Execute方法和事件。_StateChanged将状态事件与 GetChunk 方法一起使用

于 2012-07-16T14:43:28.617 回答