Internet Explorer上的宏可以在f8上正常工作,但在f5上会弹出不匹配错误

时间:2018-06-21 08:53:51

标签: excel excel-vba vba

我正在处理一个宏,该宏将打开Internet Explorer,在网站上登录,然后进行处理。宏在登录之前工作正常,并在“ MON”显示错误。还有其他一些问题:

  1. 在调试(使用f8)时,宏工作正常,但在使用F5运行时,会弹出错误,提示“ MON”出现“类型不匹配错误13”。有人可以提出原因吗?
  2. 在定义Mon时,哪种定义最适合使用?
  3. 是否还有其他方法可以从Internet Explorer的下拉列表中进行选择。
  4. 如果任何人都可以提供无需使用Shell即可切换到打开的Internet Explorer的代码,这将对您大有帮助。

我们也使用了额外的等待时间,例如“ 1分钟”,但是问题仍然存在。

Sub Intex()
    Set ie = Createobject("internetexplorer.application")  
    ie.visible = ture
    ie.navigate Range("URL").Value

    Application.wait(now + timevalue("00:00:15"))
    Set Login_Id = ie.document.getelementbyid("LoginID")
    Login_id.value = ****
    Set Login_pass = ie.document.getelementbyid("Password")
    Login_pass.value = ****  
    ie.document.form(0). submit
    Application.wait(now + timevalue("00:00:15"))

    Set Mon= ie.document.getelementbyid("ddlReportingMonth")

    For i= 0 to Mon.options.length
       If Mon.Options(i).Text = Range("Rep_Mon").value
            Mon.selectindex = i
            Exit For
       End If

    Next i

预先感谢

1 个答案:

答案 0 :(得分:0)

不用等待页面加载所需的时间

WITH j AS (
SELECT json_array_elements('[{"sym":"BTC","enn":"Bitcoin","fan":"","prc":7284.46,"c24":-4.33,"mkc":124460367747.02,"mkp":0},{"sym":"ETH","enn":"Ethereum","fan":"","prc":571.735,"c24":-5.23,"mkc":57166582578.235,"mkp":0},{"sym":"XRP","enn":"Ripple","fan":"","prc":0.625291,"c24":-6.28,"mkc":24539115471.842476,"mkp":0},{"sym":"BCH","enn":"Bitcoin Cash","fan":"","prc":1034.65,"c24":-7.09,"mkc":17771148400,"mkp":0},{"sym":"EOS","enn":"EOS","fan":"","prc":13.2186,"c24":-7.95,"mkc":11845841674.9512,"mkp":0}]'::json) AS sym
)
SELECT *
FROM j
WHERE j.sym->>'sym'= 'BTC';

                                              sym                                               
------------------------------------------------------------------------------------------------
 {"sym":"BTC","enn":"Bitcoin","fan":"","prc":7284.46,"c24":-4.33,"mkc":124460367747.02,"mkp":0}
(1 Zeile)

尝试使用以下几行:

Application.wait(now + timevalue("00:00:15"))

在尝试设置Mon变量时应该可以解决您的错误