2014-02-23 50 views
1

我有一個功能齊全的宏,它通過人員記錄列表,如果他們是離開人員或從未開始工作。唯一的問題是它的一個非常緩慢的過程,搜索(〜10000個字符)所有的HTML代碼創建的字符串時Excel VBA HTML檢索

我想知道是否有限制檢索是網頁的只是一部分的方式

我目前使用的宏下,經過各行這個宏迭代和長10000個字符從URL中的每個人的人員頁

Sub RetrieveEndDate() 
Dim myArray() As Variant, Search As Variant 
Dim strURL As String, strCSV As String, dbClose As String 


Application.ScreenUpdating = False 
Application.Calculation = xlCalculationManual 


Call LogOn 


RowsWithData = Application.CountA(Range("A:A")) 

For R = 2 To RowsWithData 

Application.StatusBar = R & " Out of " & RowsWithData 


UKNo = Cells(R, 1).Value 
    strURL = "http://www.pers.fs.com/People_Detail.asp?Pers_no=" & UKNo &  "&mode=CURRENT" 

Set http = CreateObject("MSXML2.XMLHTTP") 
    http.Open "GET", strURL, False 
    http.Send 
    strCSV = http.responseText 

    Cells(R, 3).Value = strCSV 
'Works of if employee has left, never started or if neither of them leaves blank 
    If InStr(1, strCSV, "Employee has Left") > 0 Then 
     Cells(R, 2).Value = "Left" 

    ElseIf InStr(1, strCSV, "Non-Starter") > 0 Then 
     Cells(R, 2).Value = "Did not start" 

    Else 
     Cells(R, 2).Value = "" 

    End If 


Set http = Nothing 

Next R 

1 

Application.ScreenUpdating = True 
Application.Calculation = xlCalculationAutomatic 

End Sub 

從網頁中獲取是〜代碼拉,但信息我感興趣的是在頁面的開始部分,如下面的「(員工已經離開)」,這是從底線第三

<head> 

<title> List</title> 

<link rel="stylesheet" href="_stylesheets/atc.css" type="text/css"> 

</head> 



<body CLASS="Skill" > 

<form name="People_Detail" method="Post" action=History_list.asp> 

<P><INPUT id="Pers_No" type = "HIDDEN" name="Pers_No" value=UK111111 ></P> 

<P><INPUT id="mode" type = "HIDDEN" name="mode"Value="HISTORY_LIST"></P> 









    <Table Border = 0 CellPadding = 0 width = 100% > 



<TR><TR><TD Colspan = 2 ><H1 id=Test name=test>Current Active Record<BR>(Employee has Left)</H1><TD align = right> 



    <P><INPUT id="btnSubmit" name="btnSubmit" type="SUBMIT" value="View Record History List"></P> 

    </TD></TD></TR></TR> 

回答

0

AFAIK有沒有辦法用XMLHTTP做到這一點。

This KB article包含使用WinInet API執行下載的代碼。

While bDoLoop循環讀取Len(sReadBuffer)塊中的URL,您可以修改它以添加一個條件並隨時退出循環。

如果您想要以特定的偏移量開始下載(並且服務器支持它),則還可以嘗試InternetSetFilePointer

0

我有一個類似的問題。在某個網站上的響應文本非常大,以至於我一直在尋找它的宏。我提出的解決方案如下。首先,我在響應文本上使用了SPLIT功能。

arr_1 = Split(my_var, "zc-st-a", -1, vbTextCompare) 

您沒有提供足夠的源代碼,我要具體,但通常有一些標籤,你可以在那一剎那打破了響應文本分解成你想要的數據數組元素,並沒有這些元素有用的信息。接着使用過濾功能在arr_1過濾掉無用的元素

arr_2 = Filter(arr_1, "zc-pg-y", True, vbTextCompare) 

最後,你可以結合使用JOIN功能存在於arr_2有用的元素。

​​

以我的情況下,使用這種方法,使響應文本較小的還原我的宏運行時間爲1小時15分鐘到15分鐘。希望這可以幫助