Vba 当仅显示提交按钮时,从web下载文件时收到错误

Vba 当仅显示提交按钮时,从web下载文件时收到错误,vba,excel,Vba,Excel,我需要从web下载文件,但只有提交按钮。 没有用于直接访问文件的url。 我试图通过按钮id捕捉按钮,但VBA删除了运行时错误“424”(需要对象)。 代码如下: Sub keler_submit() Application.ScreenUpdating = False Set IE = CreateObject("InternetExplorer.Application") IE.navigate "https://www.keler.hu/T%C3%A1r

我需要从web下载文件,但只有提交按钮。
没有用于直接访问文件的url。
我试图通过按钮id捕捉按钮,但VBA删除了运行时错误“424”(需要对象)。
代码如下:

Sub keler_submit()  
    Application.ScreenUpdating = False  
    Set IE = CreateObject("InternetExplorer.Application")  
    IE.navigate "https://www.keler.hu/T%C3%A1rsas%C3%A1gi%20esem%C3%A9nyek/"  
    While IE.Busy  
        DoEvents  
    Wend  
    Set doc = IE.document  
    gomb = doc.getElementById("ctl00_wpm_UserControlPortlet1682286671_ctl00_wpm_UserControlPortlet1682286671_userControlPortlet_DownloadButton1")  
    gomb.submit  
    Set IE = Nothing  
    Application.ScreenUpdating = True  
End Sub  

提前感谢

这些行不正确:

gomb = doc.getElementById("ctl00_wpm_UserControlPortlet1682286671_ctl00_wpm_UserControlPortlet1682286671_userControlPortlet_DownloadButton1")  
gomb.submit
doc.getElementById返回一个对象类型,因此需要使用Set将其分配给变量。然后应单击您尝试访问的元素,而不是提交。IE很有可能会显示一个“是否打开或保存此文件”对话框,因此请首先使IE对象可见以显示以下内容:

IE.visible = True
Set gomb = doc.getElementById("ctl00_wpm_UserControlPortlet1682286671_ctl00_wpm_UserControlPortlet1682286671_userControlPortlet_DownloadButton1")  
gomb.click

您还需要一个循环来确保页面已加载。以下工作:

Option Explicit

Public Sub GetInfo()
    Dim IE As New InternetExplorer

    With IE
        .Visible = True
        .navigate "https://www.keler.hu/T%C3%A1rsas%C3%A1gi%20esem%C3%A9nyek/"

        While .Busy Or .readyState < 4: DoEvents: Wend
        Do
            Dim b As Object
            On Error Resume Next
            Set b = .document.getElementById("ctl00_wpm_UserControlPortlet1682286671_ctl00_wpm_UserControlPortlet1682286671_userControlPortlet_DownloadButton1")
            On Error GoTo 0
        Loop While b Is Nothing

        b.Click
        'Handle save button

        'Quit '<== Remember to quit application
    End With
End Sub
选项显式
公共子GetInfo()
Dim IE成为新的InternetExplorer
与IE
.Visible=True
.导航“https://www.keler.hu/T%C3%A1rsas%C3%A1gi%20esem%C3%A9nyek/"
当.Busy或.readyState<4:DoEvents:Wend时
做
将b作为对象
出错时继续下一步
Set b=.document.getElementById(“ctl00\u wpm\u UserControlPortlet1682286671\u ctl00\u wpm\u UserControlPortlet1682286671\u userControlPortlet\u DownloadButton1”)
错误转到0
循环,而b什么都不是
b、 点击
'句柄保存按钮
“退出”