我在VBA中使用xml。下面的代碼將項目添加到遠程網站上的購物車(發佈表單)。然後代碼在Internet Explorer中顯示結果。在自動化XML表單發佈之後的VBA中,我如何自動與響應進行交互?
你可以在響應中看到有一個「get estimate」按鈕。我需要自動點擊它,輸入位置信息,並在我的Excel 2010工作表上獲得運費和稅費(針對當前購物車中的物品)的回覆。
我希望所有的自動點擊和輸入數據都與網站(網站的服務器?)一起發生,就像我將商品添加到購物車時一樣,而不是通過瀏覽器(如果可能)。加載頁面需要很長時間,我認爲如果通過瀏覽器瀏覽我無論如何都可以做到這一點。但是我真的被卡住了,所以如果我必須加載一個瀏覽器也沒關係。
Option Explicit
Sub testing()
Dim objIE As Object
Dim xmlhttp As Object
Dim response As String
Set objIE = CreateObject("InternetExplorer.Application")
objIE.navigate "about:blank"
objIE.Visible = True
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
'~~> Indicates that page that will receive the request and the type of request being submitted
xmlhttp.Open "POST", "http://www.craft-e-corner.com/addtocart.aspx?returnurl=showproduct.aspx%3fProductID%3d2688%26SEName%3dnew-testament-cricut-cartridge", False
'~~> Indicate that the body of the request contains form data
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
'~~> Send the data as name/value pairs
xmlhttp.Send "Quantity=1&VariantID=2705&ProductID=2688"
response = xmlhttp.responseText
objIE.Document.Write response
Set xmlhttp = Nothing
End Sub
如果你谷歌的「VBA automate IE」,你會得到很多這種類型的任務的例子。例如:http://www.jpsoftwaretech.com/excel-vba/automate-internet-explorer/ – 2012-01-11 00:50:27
不,我需要層層的事情發生,而不是1件事。我能夠做一件事情,而不需要進一步的自動事件層。 – user1140067 2012-01-11 00:55:56
我也搜索了無濟於事,你發佈的教程是加載瀏覽器的VBA無xmlhttp交互。 – user1140067 2012-01-11 01:03:24