VBA:跟随现有会话中的链接 – Excel

我们有一个有很多参数的URL列表。 问题是:第一次跟随一个链接,你会被redirect到ADFS-Login,这会削减一些参数,因为它们有一个最大的URL长度。

我的问题:有没有可能告诉Excel(通过VBA或默认)来使用现有的会话?

我尝试了一些神器,例如通过Chrome浏览器: find一个Chrome浏览器的窗口句柄或采取现有的IE窗口: http ://www.mrexcel.com/forum/excel-questions/553580-visual-basic-applications -macro-already-open-ie-window.html当我得到一个现有的窗口,它似乎总是被redirect和URL的切割。 有没有可能做到这一点?

请尝试这个并发表反馈

  1. 打开Sheet1
  2. 在列A中,从第2行创buildURLS列表
  3. 插入ActiveXControl Microsoft Web浏览器WebBrowser1
  4. 根据您的需要调整控件的大小
  5. 将控制button插入浏览器的边界之外
  6. 将该button的名称更改为NextButton

打开代码编辑器(Alt + F11)

在Sheet1中放置下面的代码

Dim currentURLRow As Integer ''Sheet level variable Sub NextButton_Click() On Error Resume Next Dim url As String ''VBA evaluates second expression even when the first of OR is true. So on error resume next helps here If currentURLRow = 0 Or Trim(Cells(currentURLRow, 1)) = "" Then ''First time or loop back currentURLRow = 2 Else currentURLRow = currentURLRow + 1 End If On Error GoTo 0 ''reset error so you know of any (good) errors url = Cells(currentURLRow, 1) ''Sheet1.WebBrowser1.Silent = True ''Uncomment this if you are seeing lot of script errors that you dont want to see WebBrowser1.Navigate url Debug.Print WebBrowser1.Document.body.InnerHTML ''' Here you can do magic if the urls you are navigating are serialisable to objects :) End Sub 

现在,您第一次浏览该网站时,系统会提示您input用户名和密码,点击下一步,保存您的会话。