简体   繁体   English

自动关闭警报/弹出窗口VBA

[英]Close alert / pop-up window automatically VBA

Please try the code below, what is doing is downloading some data from the surface of a webpage, but I need it to work automatically and the proble appears when opening the Excel, the pop-up window. 请尝试下面的代码,这是从网页表面下载一些数据,但是我需要它自动运行,并且在打开Excel弹出窗口时出现问题。 Is there any way to get rid of it automatically pressing ENABLE? 有什么方法可以自动按一下ENABLE来摆脱它吗?

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Sub DownPDF()
' This macro downloads the pdf file from webpage
' Need to download MSXML2 and MSHTML parsers and install
Application.OnTime Now + TimeValue("00:01:10"), "DownPDF"
Dim sUrl As String
Dim xHttp As MSXML2.XMLHTTP
Dim hDoc As MSHTML.HTMLDocument
Dim hAnchor As MSHTML.HTMLAnchorElement
Dim Ret As Long
Dim sPath As String
Dim i As Long

sPath = "C:\Documents and Settings\ee28118\Desktop\Ordine\"
sUrl = "http://cetatenie.just.ro/wp-content/uploads/"

'Get the directory listing
Set xHttp = New MSXML2.XMLHTTP
xHttp.Open "GET", sUrl
xHttp.send

'Wait for the page to load
Do Until xHttp.readyState = 4
    DoEvents
Loop

'Put the page in an HTML document
Set hDoc = New MSHTML.HTMLDocument
hDoc.body.innerHTML = xHttp.responseText

'Loop through the hyperlinks on the directory listing
For i = 0 To hDoc.getElementsByTagName("a").Length - 1
    Set hAnchor = hDoc.getElementsByTagName("a").Item(i)

    'test the pathname to see if it matches your pattern
    If hAnchor.pathname Like "Ordin-*.2013.pdf" Then
        Ret = URLDownloadToFile(0, sUrl & hAnchor.pathname, sPath & hAnchor.pathname, 0, 0)

        If Ret = 0 Then
            Debug.Print sUrl & hAnchor.pathname & " downloaded to " & sPath
        Else
            Debug.Print sUrl & hAnchor.pathname & " not downloaded"
        End If
    End If
Next i

End Sub

try setting your Excel Security level very high or low on the desktop then Exel won't protect you from malicious code that might run when you open a workbook (but a good anti-virus software will do it anyway!) 尝试在桌面上将Excel安全级别设置得很高或很低,则Exel不会保护您免受打开工作簿时可能运行的恶意代码的影响(但是无论如何,好的反病毒软件都可以做到!)

  • Very High means it won't ask you 很高意味着它不会问你
  • Low means it won't ask you. 低意味着它不会问你。

HTH HTH

Philip 菲利普

The reason why it asks you to enable Macros is because a macro can actually harm to your PC. 之所以要求您启用宏,是因为宏实际上会损害您的PC。 It is a security issue and you cannot override that feature automatically through VBA. 这是一个安全问题,您不能通过VBA自动覆盖该功能。

A person has to manually go to Excel: "Trust Center->Trust Center Settings->Macro Settings->Enable all macros(not recommended; potentially dangerous code can run)" 一个人必须手动转到Excel:“信任中心->信任中心设置->宏设置->启用所有宏(不建议使用;可能运行潜在危险的代码)”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM