首页 > 解决方案 > 如果窗口被锁定,宏不会循环

问题描述

我有这个从互联网页面抓取数据的宏:

Sub SA()

Application.ScreenUpdating = False

'# Ouvre une fenetre Internet Explorer
Set ie = New InternetExplorerMedium

With ie
.navigate "http://pfrwtekref/websail/"
While .readyState <> 4: DoEvents: Wend
Application.Wait Now + TimeValue("0:00:01")
.Visible = False
Set frm = .document.getElementById("Form1")
'# Connection à Sail
    With frm
   .elements("txtLogin").Value = private
   .elements("txtPwd").Value = private
   .elements("Button1").Click
   End With
Application.Wait Now + TimeValue("0:00:01")
While .readyState <> 4: DoEvents: Wend
.navigate "http://pfrwtekref/websail/frmSuiviActivite.aspx"
Application.Wait Now + TimeValue("0:00:01")
'# Recupere les données dans deux cellules données
Set frm = .document.getElementById("Form1")
Application.Wait Now + TimeValue("0:00:01")

'Se place sur la ligne apres la derniere ligne du tableau
lign = Cells(Rows.Count, 1).End(xlUp).Row
lignL = lign + 1
    With frm
    'Recupere les données dans la feuille cockpit et les inscrit dans le tableau de suivi d'activité (SA)
        WSSA.Cells(lignL, 1) = Date
        WSSA.Cells(lignL, 2) = Time
        WSSA.Cells(lignL, "C") = .all(11).innerText
        WSSA.Cells(lignL, "F") = .all(12).innerText
        WSSA.Cells(lignL, "D") = .all(37).innerText
        WSSA.Cells(lignL, "G") = .all(38).innerText
        WSSA.Cells(lignL, "E") = .all(37).innerText
        WSSA.Cells(lignL, "H") = .all(38).innerText
    End With
'# Ferme la fenêtre Internet
.Quit
End With

'Supprime tout les "/" qui auraient pu se glisser dans la ligne
WSSA.Range("C" & lignL & ":D" & lignL).Replace What:="/*", Replacement:=""
WSSA.Range("F" & lignL & ":G" & lignL).Replace What:="/*", Replacement:=""
WSSA.Range("E" & lignL).Replace What:="*/", Replacement:=""
WSSA.Range("H" & lignL).Replace What:="*/", Replacement:=""

    Application.OnTime Now + TimeValue("00:15:00"), "SA.SA"

Application.ScreenUpdating = True
End If
End Sub

当我让它在后台运行时效果很好,但如果我的 Windows 会话被锁定,我的宏不再循环(每 15 分钟)。你知道是否有办法解决这个问题?

谢谢,祝你有美好的一天!

标签: excelvbaloopsinternet-explorer

解决方案


推荐阅读