2017-03-29 37 views
0

我正在尋找一個代碼來將數值從一個Excel到一個網頁。VBA來完成一個Internet表格

Sub FillInternetForm() 
    Dim IE As Object 
    Set IE = CreateObject("InternetExplorer.Application") 

    IE.navigate "http://xxxxxxxx/" 
    IE.Visible = True 
    While IE.Busy 
    DoEvents 
    Wend 
    IE.document.getElementById("xxxxx").Value = "xxxx" 
End Sub 

的錯誤出現在IE.document.getElementById( 「XXXXX」)。值=「XXXX線和它說對象的方法 '文件''IWebBrowser 2失敗。

我尋找suggstions來解決這個問題:我做了很多的研究,並沒有什麼作品:/

提前:)

+0

我可以建議一種不同的方法。你有沒有看到這篇文章http://stackoverflow.com/questions/158633/how-can-i-send-an-http-post-request-to-a-server-from-excel-using-vba – Miguel

+0

嘗試'同時ie.Busy或ie.READYSTATE <> 4' – Jeeped

+0

@謝謝你的幫助。不幸的是它沒有工作:( –

回答

0

安娜謝謝, 這裏是一個工作示例,您可以輕鬆地定製的代碼這一點。爲你工作,有一次你必須意識到這一點我在工具 - >首選項 - > Microsoft Internet Controls下添加了對我的項目的參考。另外還有一個值得警惕的字眼是這條線上的Set Elements,如果你正在尋找一些不存在的東西,你最終會報錯。我將這個工作示例放到堆棧溢出中,並找到footer-menu以下的元素。 讓我知道是否沒有任何意義。

Sub TryInternetExplorer() 
'Reference to system32\shdocvw.dll 'Microsoft Internet Controls 
Dim IEApp As InternetExplorer 
Set IEApp = New InternetExplorer 
IEApp.Visible = True 
IEApp.Navigate "https://iam.pearson.com/auth/XUI/#login/" 
While IEApp.ReadyState <> READYSTATE_COMPLETE And IEApp.ReadyState <> READYSTATE_LOADED 
    DoEvents 
Wend 

'wait for the form to load 
Do 
Set form = IEApp.Document.getElementsByTagName("FORM")(0) '1st table 
DoEvents 
Loop While form Is Nothing 

IEApp.Document.getElementsByName("callback_0")(0).Value = "Miguel" 
IEApp.Document.getElementsByName("callback_1")(0).Value = "pass" 
IEApp.Document.getElementsByName("callback_2")(0).Click 


Set Document = Nothing 
Set IEApp = Nothing 


End Sub 
+0

Miguel:424 :需要的對象:( –

+0

安娜你添加了參考,因爲我告訴過你嗎? – Miguel

+0

是的,我做到了!@miguel –

相關問題