Excel VBA, I get a prompt “Windows security” when accessing an URL

久未见 提交于 2020-07-08 10:37:33

问题


I Have an Excel file that access an URL HTTPS. The URL as a basic authentication with username and password.

This macro is running every morning and night. It need it to be AUTOMATIC. I have the username and password.

The problem is that each time I run the macro, it Prompt me for the "Windows security". The user name and password is already fill up because I did add this connection in my credential. The "windows security" just wait for a user to click enter. This macro should run automaticly and can't wait for someone to click OK.

I did try VBS Script to login but it only work when user is active on the session. See this : VBA code to pass username & password

I did also try to put the username and password in the URL like : ...

How I connect without the "Windows Security" Prompt???

Here my add connection function :

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

回答1:


If you can't control the security level of the remote machine, then I would go for one of the following solutions:

  • Use SendKeys to send the Enter key, or equivalent keystroke that will 'click' the button for you. Use a timer to wait 2-3 seconds after you authenticate to then send the Enter key so it won't send Enter before the msgbox is displayed.

  • Use Windows API to get the handle for the security message popup, you can then control it programmatically.




回答2:


sometimes the security on the browser security is the issue so you can try and and declare Internet explorer as so;

Dim IE as New InternetexplorerMedium

or

try decreasing macro security under the developer options

or

go to internet options and decrease the security level but be warned this is dangerous and is not usually recommended

if you need more assistance you can email me on howtovba@gmail.com

or go my youtube page and leave a comment on what youd like a video on to be assisted with https://www.youtube.com/watch?v=hfAhmae4iqA



来源:https://stackoverflow.com/questions/30916287/excel-vba-i-get-a-prompt-windows-security-when-accessing-an-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!