即vba提交功能不起作用

时间:2015-08-06 12:30:39

标签: vba internet-explorer passwords submit

我成功传递了第一个密码页面,但在第二页中,同一个提交功能不起作用,我无法通过最后一个(第三个)页面。我试图将查询结果带到Excel。提交功能不起作用,它保留在第二页。按钮名称也是“提交”。相同的功能适用于第一页但不适用于第二页,我是新手,对不起,如果这是一个愚蠢的问题。

这些页面是在本地网站上进行的,因此我无法与您分享。提前谢谢

Sub GetTable()

Dim ieApp As InternetExplorer
Dim ieDoc As Object
Dim ieSorgu As Object
Dim ieTable As Object
Dim clip As DataObject
Dim LoginForm As HTMLFormElement
Dim SorguForm As HTMLFormElement

'create a new instance of ie
Set ieApp = New InternetExplorer

'you don’t need this, but it’s good for debugging
ieApp.Visible = True

'assume we’re not logged in and just go directly to the login page
ieApp.Navigate "http://sample/"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop


Set ieDoc = ieApp.Document
Set LoginForm = ieDoc.forms(0)

'fill in the login form – View Source from your browser to get the control names
With ieDoc.forms(0)
    .user_name.Value = "admin"
    .pass.Value = "password"
    LoginForm.submit

End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop


'now that we’re in, go to the page we want
ieApp.Navigate "http://sample/rapor_goruntule.php?style=saatlik"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop


Set SorguForm = ieDoc.forms(0)
With ieDoc.forms(0)
    .filtre_kuyruk.Value = "0"  'these values are for query
    .saat_periyot.Value = "01:00:00"
    .mesai_start_sa.Value = "08"
    .mesai_start_dk.Value = "00"
    .mesai_start_sn.Value = "00"
    .mesai_end_sa.Value = "18"
    .mesai_end_dk.Value = "00"
    .mesai_end_sn.Value = "00"
    .filtre_kullanici.Value = "0"
    .bekleme_uzun_sa.Value = "0"
    .bekleme_uzun_dk.Value = "00"
    .bekleme_uzun_sn.Value = "00"
    .islem_kisa_sa.Value = "00"
    .islem_kisa_dk.Value = "00"
    .islem_kisa_sn.Value = "00"
    .islem_uzun_sa.Value = "00"
    .islem_uzun_dk.Value = "00"
    .islem_uzun_sn.Value = "45"
    .work_start_sa.Value = "08"
    .work_start_dk.Value = "00"
    .work_start_sn.Value = "00"
    .work_end_sa.Value = "18"
    .work_end_dk.Value = "00"
    .work_end_sn.Value = "00"
    SorguForm.submit

    End With




Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
'get the table based on the table’s id
Set ieDoc = ieApp.Document
Set ieTable = ieDoc.all.Item("sampletable")

'copy the tables html to the clipboard and paste to teh sheet
If Not ieTable Is Nothing Then
    Set clip = New DataObject
    clip.SetText "<html>" & ieTable.outerHTML & "</html>"
    clip.PutInClipboard
    Sheet1.Select
    Sheet1.Range("A1").Select
    Sheet1.PasteSpecial "Unicode Text"
End If

'close 'er up
ieApp.Quit
Set ieApp = Nothing

End Sub

1 个答案:

答案 0 :(得分:0)

我认为您的问题是您没有为文档重新分配对象引用,因此当您尝试访问表单集时,您实际上是在尝试再次提交原始表单,而不是您想。

尝试在分配SoguForm变量之前添加重新分配:

Set ieDoc = ieApp.Document
Set SorguForm = ieDoc.forms(0)