簡體   English   中英

Excel VBA - Win10,IE11 - 打開第二個網頁不起作用

[英]Excel VBA - Win10, IE11 - opening second webpage is not working

我們已經遷移到 win10 和 IE11 並且我的一些 vba 宏停止工作。 我可以解決一些問題,但我在解決以下問題時遇到了問題。

我有一個宏,可以在 IE 中打開一個網頁。 打開這個網頁只是為了登錄數據庫。 有一份客戶名單。 每個客戶都有特定的 ID,這也反映在 URL 中。 我沒有搜索 html 代碼,而是簡單地將這個客戶特定的 URL 輸入到 IE。 問題是,這在 Win 10 IE11 上停止工作。 第一個頁面(用於登錄的頁面)打開了,但是沒有輸入第二個 URL 並且宏在等待第二個時卡住,加載客戶特定頁面。 還有我需要訪問的第三頁,它的 URL 對於每個客戶都是相同的,這就是為什么我需要先訪問登錄頁面,然后是客戶特定頁面,然后是該客戶設備列表的第三頁。 直接進入設備列表頁面不起作用。 另外,我沒有收到任何錯誤或類似的東西。

這是我的代碼:

        Dim ie As Object
        Set ie = CreateObject("InternetExplorer.Application")

        ie.Visible = True
        ie.Document.Focus

        ie.Navigate "https://webpage_used_to_log_in.com"
        While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
            DoEvents
        Wend

        ie.Navigate = "https://customer_specific_webpage.com"
        While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
            DoEvents                         'the macro stucks here as customer page is never entered and opened
        Wend

        ie.Navigate = "https://device_list.com"
        While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
            DoEvents  
        Wend                       

這在 Win7 和 IE11 中完美運行。 我找不到這個問題的任何解決方案。 如果您知道如何解決此問題,我將非常感謝您的幫助。 謝謝你。

也許第二個和第三個ie.Navigate中的等號=會導致問題。 我認為這是一種錯誤的表達方式。 下面的代碼在我win10的IE11中可以正常運行,你可以試試:

Sub LOADIE()
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True

    ie.Navigate "https://www.google.com"
    While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Wend

    ie.Navigate "https://www.stackoverflow.com"
    While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Wend

    ie.Navigate "https://www.bing.com"
    While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Wend
End Sub

這是行不通的:

While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
  DoEvents
Wend

您設置相反的條件,即瀏覽器必須處於忙碌狀態或ReadyState必須設置為Complete才能繼續循環。 所以這是一個無限循環。

這是它的工作原理:

Sub LOADIE()
  Dim ie As Object
  Set ie = CreateObject("InternetExplorer.Application")
  ie.Visible = True

  ie.Navigate "https://www.google.com"
  Do Until ie.ReadyState = 4: DoEvents: Loop

  ie.Navigate "https://www.stackoverflow.com"
  Do Until ie.ReadyState = 4: DoEvents: Loop

  ie.Navigate "https://www.bing.com"
  Do Until ie.ReadyState = 4: DoEvents: Loop
End Sub

您所要做的就是檢查busyReadyState 我也想知道如果根本沒有登錄,為什么必須調用登錄頁面。

此致

茲文

這對我有用:

    Dim ie As Object
    Set ie = New InternetExplorerMedium  'used this to fix the issue with reading data from html code

    ie.Visible = True
    ie.Document.Focus

    ie.Navigate "https://webpage_used_to_log_in.com"
    Do Until.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Loop

    ie.Navigate = "https://customer_specific_webpage.com"
    Do Until.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Loop

    ie.Navigate = "https://device_list.com"
    Do Until.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Loop   

謝謝大家的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM