好的,我在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#中,我使用以下代码填充TextBox值:
webBrowser1.Document.GetElementById("ITEMID").SetAttribute("value", id);
如何在VBA中复制它?
答案 0 :(得分: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
答案 1 :(得分: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