我已经尝试了很多变种,但是我认为这是我最接近使其起作用的方法,而我根本不知道如何进行。
这是基本概念。 我有一个URL,它将触发XLS格式文件的创建和下载。 我的代码使用sendkeys来完全打开此文件(%a接受安全警告(如果有办法,请跳过此步,在这一点上,我需要基本确保从下载中打开的文件是活动窗口,请注意下载的文件名可能会略有不同。
我尝试的其他事情仍然有一些垃圾。
问题:如何确保直到活动窗口是MyBrowser(IE)还是我刚刚使用发送键打开的Excel工作簿,否则如何循环播放?
Sub SearchRepQ()
Dim USER1 As String
'USER1 = Application.WorksheetFunction.Index(Sheets("SRC").Range("D:D"), Application.WorksheetFunction.Match(UserForm1("TextBox1"), Sheets("SRC").Range("C:C"), 0))
Dim prefix1 As String
Dim prefix2 As String
prefix1 = "https://MyReports.com/default.aspx?&sk=Mgmt+Console&s=~_d0!2!1!!1!7!0!1!!2!!!0!1!3!2!_d2!"
prefix2 = "!Central+Standard+Time!_d6!fvf%7c%40ticketowner!DrurxrErsrzqFqypvspwpxpCpvtpwpwpqBqypvspwpxpApvtpwpwpqqrzqqqrur!fvf%7c%40ticketstatusopenclosed!_d0!4!Mgmt+Console!Open!_d1!_d8!!yqHqtFpGpxpvppupxpupvpupwppwpppupvpKpJpIpEpzpBpApCppDpqyprpqsq!&xls=h$Mgmt_32_Console$ctl00$mup$t$ctl00$ctl00$exl"
Dim MyURL1 As String
Dim MyURL2 As String
MyURL1 = ("https://MyReports.com")
MyURL2 = (prefix1 & USER1 & prefix2)
Dim MyBrowser As SHDocVw.InternetExplorer
Set MyBrowser = New InternetExplorer
Dim XL As Excel.Application
'Dim IEe As New IEEvents
Set XL = Excel.Application
'Set IEe.IEApp = MyBrowser
MyBrowser.Silent = True
MyBrowser.Visible = True
MyBrowser.navigate MyURL1
Do Until MyBrowser.READYSTATE = READYSTATE_COMPLETE: DoEvents: Loop
MyBrowser.navigate MyURL2
Do Until MyBrowser.READYSTATE = READYSTATE_COMPLETE: DoEvents: Loop
VBA.AppActivate MyBrowser.document.Title & " - " & MyBrowser.Name, 0
Application.Wait (Now + TimeValue("0:00:3"))
SendKeys "%(o)"
Application.Wait (Now + TimeValue("0:00:1"))
SendKeys "%(a)"
'Dim counter As Integer
' Set counter = 0
'Dim number As Integer = 8
'Do Until number = 10
' If number <= 0 Then Exit Do
' number -= 1
' counter += 1
'Loop
VBA.AppActivate XL.ActiveWindow.Activate.Title("coveo*", 0)
end sub