VB打开网页并自动提交表单问题。 10
'*****连接网站自定义函数*********PublicFunctionDCUrl(strUrlAsString,strUserAsString,strPasswor...
'*****连接网站自定义函数*********
Public Function DCUrl(strUrl As String, strUser As String, strPassword As String) As Boolean
Dim IE As Object, timeie As Date
Dim READYSTATE_COMPLETE As Boolean
'frmDC.Show
On Error Resume Next
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
'连接网站时,窗口最小化
ShowWindow IE.hwnd, 3
'IE.vbMaximizedFocus
'IE.FullScreen = True
'IE.SetFocus = True
WindowState = vbMinimized
frmDC.Visible = False
IE.Navigate strUrl
timeie = DateAdd("s", 60, Now()) '最久等待60秒
Do While IE.Busy And Not IE.ReadyState = READYSTATE_COMPLETE
DoEvents
If timeie < Now() Then
MsgBox "无法连接网站,请重新执行"
IE.Quit
Exit Function
End If
Loop
IE.Document.All.UserName.Value = strUser
IE.Document.All.Password.Value = strPassword
IE.Document.All.Submit0.Click
End Function
主窗体中有text1和text2,command1控件。
strUser=text1.text
strPassword=text2.text
点击command1时调用
DCUrl函数,打开网页并输入用户名和密码,并提交网页表单。
存在问题:当不是使用IE作为默认浏览器时,出现无法执行的情况。现在我使用的是搜狗浏览器。 展开
Public Function DCUrl(strUrl As String, strUser As String, strPassword As String) As Boolean
Dim IE As Object, timeie As Date
Dim READYSTATE_COMPLETE As Boolean
'frmDC.Show
On Error Resume Next
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
'连接网站时,窗口最小化
ShowWindow IE.hwnd, 3
'IE.vbMaximizedFocus
'IE.FullScreen = True
'IE.SetFocus = True
WindowState = vbMinimized
frmDC.Visible = False
IE.Navigate strUrl
timeie = DateAdd("s", 60, Now()) '最久等待60秒
Do While IE.Busy And Not IE.ReadyState = READYSTATE_COMPLETE
DoEvents
If timeie < Now() Then
MsgBox "无法连接网站,请重新执行"
IE.Quit
Exit Function
End If
Loop
IE.Document.All.UserName.Value = strUser
IE.Document.All.Password.Value = strPassword
IE.Document.All.Submit0.Click
End Function
主窗体中有text1和text2,command1控件。
strUser=text1.text
strPassword=text2.text
点击command1时调用
DCUrl函数,打开网页并输入用户名和密码,并提交网页表单。
存在问题:当不是使用IE作为默认浏览器时,出现无法执行的情况。现在我使用的是搜狗浏览器。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询