Excel VBA,我在访问URL时得到提示"Windows安全性"

use*_*101 5 excel vba excel-vba

我有一个访问URL HTTPS的Excel文件.URL作为基本身份验证,包含用户名和密码.

这个宏每天早晚都在运行.它需要它是AUTOMATIC.我有用户名和密码.

问题是,每次运行宏时,都会提示我"Windows安全性".用户名和密码已经填满,因为我确实在我的凭据中添加了此连接."windows安全性"只是等待用户单击"输入".此宏应自动运行,不能等待某人单击确定.

我确实尝试使用VBS Script登录,但只有当用户在会话中处于活动状态时才会起作用.请参阅:VBA代码以传递用户名和密码

我也尝试将用户名和密码放在URL中,如:...

如何连接没有"Windows安全"提示???

这里我的添加连接功能:

Function GetForcast(DateStart As String, DateEnd As String)


    Sheets("Forecast RAW").Select
    With Sheets("Forecast RAW").QueryTables.Add(Connection:= _
        "URL;https://weather.dtn.com/basic/rest-3.4/obsfcst.wsgi?dataTypeMode=0001&dataType=HourlyForecast&startDate='" & DateStart & "'T00:00:00Z&EndDate='" & DateEnd & "'T00:00:00Z&stationID=KILG" _
        , Destination:=range("$A$1"))
        .Name = "00Z&stationID=KILG"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = True
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        'Shell "WScript C:\Temp\Logon.vbs", vbNormalFocus
        .Refresh BackgroundQuery:=False
      End With

End Function
Run Code Online (Sandbox Code Playgroud)

小智 0

如果您无法控制远程计算机的安全级别,那么我会采用以下解决方案之一:

  • 使用 SendKeys 发送 Enter 键或将为您“单击”按钮的等效击键。使用计时器在身份验证后等待 2-3 秒,然后发送 Enter 键,这样在显示消息框之前就不会发送 Enter 键。

  • 使用 Windows API 获取安全消息弹出窗口的句柄,然后您可以通过编程方式控制它。