You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Excel宏相同IE Navigate代码在不同工作簿执行结果不一致

问题:IE.Navigate调用时丢失URL末尾Query参数(仅特定工作簿出现)

两个Excel工作簿的宏中,均使用Internet Explorer的Navigate方法传入字符串变量作为URL,代码逻辑一致,仅URL的拼接方式不同:

  • 工作簿A的URL通过多次调用与响应拼接生成
  • 工作簿B的URL通过单元格预存的内容拼接生成,最终字符串经监视、复制对比确认与工作簿A完全一致

异常情况:工作簿B执行IE.Navigate dataurl时,无法完整传递URL,会丢失末尾的Query部分(如?type=ST),但dataurl变量本身确实包含完整字符串。
特殊的是,如果直接写死完整URL(示例:IE.Navigate "https://www.marketwatch.com/investing/stock/aapl?Mod=search"),则可正常导航到完整地址。

使用的VB代码如下:

Function calling(dataurl As String) As String

Dim IE As InternetExplorer
Dim htmldoc As New HTMLDocument
Set IE = CreateObject("InternetExplorer.Application")
Application.StatusBar = "Setting up..."
IE.Visible = False
IE.navigate dataurl

Application.StatusBar = "Calling server..."
Application.Wait (Now + TimeValue("00:00:03"))

    Do Until IE.readyState = 4 
        IE.Refresh2 (3)
        Application.Wait (Now + TimeValue("00:00:05"))
    Loop
   calling = IE.document.body.innerHTML
   
   IE.Quit
  Set IE = Nothing
  
  Application.StatusBar = ""
End Function

已尝试过其他浏览器,最终仍选择使用Internet Explorer。

内容的提问来源于stack exchange,提问作者Javamaral

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 13:32:05