|
Программное управление веббраузером
Управление MSIE как COM объектом с целью автоматизации работы с интернетом
Published by: lobodava
Public Sub EnterToMailRu()
Const conLogin As String = "UserName"
Const conPassword As String = "UserPassword"
Dim i As Integer
Dim ie As Object
Dim varReturn As Variant
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate ("http://www.mail.ru")
varReturn = SysCmd(acSysCmdInitMeter, "Entering to Mail.Ru ...", 100)
While CBool(ie.Busy) i = i + 1
varReturn = SysCmd(acSysCmdUpdateMeter, Int(i / 30000 * 100))
If i > 29999 Then varReturn = SysCmd(acSysCmdClearStatus)
Beep
MsgBox "Something is wrong. Mail.Ru is not accessible", vbCritical, "Mail.Ru"
ie.Quit
Set ie = Nothing
Exit Sub
End If
DoEvents
Wend
varReturn = SysCmd(acSysCmdClearStatus)
ie.Document.Forms.Auth.Login.Value = conLogin
ie.Document.Forms.Auth.Password.Value = conPassword
ie.Document.Forms.Auth.submit
Set ie = Nothing
End Sub
Еще Пример заполнения интернет форм из VBA
А вот так, я только что отослал SMS через сайт МТС
Правда иногда не срабатывает с первого раза :(
Public Sub Send_SMS_via_MTS_Site()
Const conLogin As String = "916692...."
Const conPassword As String = "123456"
Dim i As Integer
Dim ie As Object
Dim varReturn As Variant
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "https://www.mts.ru"
varReturn = SysCmd(acSysCmdInitMeter, "Entering to MTS.Ru ...", 100)
While CBool(ie.Busy) i = i + 1
varReturn = SysCmd(acSysCmdUpdateMeter, Int(i / 30000 * 100))
If i > 29999 Then
varReturn = SysCmd(acSysCmdClearStatus)
Beep
MsgBox "Something is wrong. MTS.Ru is not accessible", vbCritical, "MTS.Ru"
ie.Quit
Set ie = Nothing
Exit Sub
End If
DoEvents
Wend
varReturn = SysCmd(acSysCmdClearStatus)
ie.Document.Forms.loginForm.phoneNumberEdit.Value = conLogin
ie.Document.Forms.loginForm.passwordEdit.Value = conPassword
'ie.Document.Forms.loginForm.Submit - в лоб не работает, поэтому идем в обход' ie.Document.Forms.loginForm.loginButton.focus
SendKeys "{ENTER}"
While CBool(ie.Busy) i = i + 1
If i > 29999 Then Exit Sub
Wend
ie.Navigate "https://www.mts.ru/cgi-bin/cgi.exe?function=sms_send"
While CBool(ie.Busy) i = i + 1
If i > 29999 Then Exit Sub
Wend
ie.Document.Forms.Send.To.Value = "7" & conLogin
ie.Document.Forms.Send.Msg.Value = "Send SMS using VBA"
ie.Document.Forms.Send.DelayMin.focus
SendKeys "{Tab}{Tab}{ENTER}"
Set ie = Nothing
End Sub
| |