2013-10-17 37 views
0

我想出瞭如何使用vba自動登錄,但我想用嵌入式瀏覽器做同樣的事情。我嘗試過在網上找到的各種方法,但沒有成功。登錄到嵌入式網頁瀏覽器

任何人都可以指向正確的方向嗎?

這是我目前的。我想使它的 「sheet1.webbrowser1」 工作

Dim HTMLDoc As Object 
Dim oBrowser As InternetExplorer 
Sub Website_Login_Test() 

Dim oHTML_Element As Object 
Dim sURL As String 

On Error GoTo Err_Clear 
sURL = "http://example.com/login.action?os_destination=%2Fhomepage.action" 

Set oBrowser = New InternetExplorer 
oBrowser.Silent = True 
oBrowser.timeout = 60 
oBrowser.Navigate sURL 
oBrowser.Visible = True 

Do 
' Wait till the Browser is loaded 
Loop Until oBrowser.ReadyState = READYSTATE_COMPLETE 

Set HTMLDoc = oBrowser.Document 

HTMLDoc.all.os_username.Value = "this" 
HTMLDoc.all.os_password.Value = "this" 

HTMLDoc.all.os_cookie.Click 
HTMLDoc.all.login.Click 

' oBrowser.Refresh ' Refresh If Needed 
Err_Clear: 
If Err <> 0 Then 
Err.Clear 
Resume Next 
End If 
End Sub 

回答

1
Dim oBrowser As Object 
Set oBrowser = Sheet1.WebBrowser1 
oBrowser.Navigate "http://www.google.com" 
+0

感謝。這很簡單。 – halcyon27