2011-10-17 136 views
0

好吧,我有一個Microsoft Access中的WebBrowser控件,我想將一個頁面加載到控件中並填充文本框的值,並將標籤的值作爲變量返回。Microsoft Access WebBrowser控件

在任何人說出來之前,我已經用C#完成了項目,但客戶端在Access中需要它。

我的代碼加載網頁低於:

Dim strURL As String 
Dim objIE As Object 

strURL = "https://mywepage.com" 
Set objIE = Me.WebBrowser2.Object 
objIE.Navigate strURL 

在C#中,我填寫文本框的值用下面的代碼:

webBrowser1.Document.GetElementById("ITEMID").SetAttribute("value", id); 

如何複製這一在VBA?

回答

1

這裏是你可以做到這一點在VBA

Dim objCollection As Object 
Dim IE As Object 

' Create InternetExplorer Object 
Set IE = CreateObject("InternetExplorer.Application") 

' Send the form data To URL As POST binary request 
IE.Navigate "https://mywebpage.com" 

' Wait while IE loading... 
Do While IE.Busy 
    Application.Wait DateAdd("s", 1, Now) 
Loop 

Set objCollection = IE.document.GetElementById("ITEMID") 
objCollection(0).Value = "value" 

一個很明顯的例子,在這裏順便說一句:http://www.excely.com/excel-vba/ie-automation.shtml

+0

完美,謝謝你 – JMK

0

您可以訪問IE的DOM一次它的加載頁面;

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) 
    WebBrowser1.Document.Forms("search").elements("q").Value = "blah" 
    WebBrowser1.Document.getElementById(....) 
End Sub