2012-07-16 44 views
1

編輯VBA Inet1 GetChunk函數

我想調用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:對象需要」。我不知道爲什麼我會收到此錯誤消息。有什麼建議麼?

+0

僅供參考:http://stackoverflow.com/q/11437911/190829 – JimmyPena 2012-07-16 17:23:45

回答

0

.OpenURL是同步的;它會打開URL然後阻塞,直到它被完全加載到mypage變量中,所以內容已經「在一個變量名下」。

如果需要異步讀取,則需要使用.Execute方法& _StateChanged事件。 (Using the State Event with the GetChunk Method

+0

亞歷克斯,你可以檢查編輯?我仍然遇到問題。 – sresht 2012-07-25 20:06:57