我正在尝试使用InternetExplorer.Application下载文件,但始终会打开一个窗口,要求保存或打开文件。有没有办法避免这种情况,并将其运行并保存在后台?这是我尝试过的代码块。
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "https://pastebin.com/raw/terAweb"
State = 0
Do Until State = 4
DoEvents
State = ie.readyState
Loop
Dim file: file= ie.Document.Body.innerHTML
使用URL Monikers API而不是尝试与InternetExplorer Application进行通信可能会更简单。这是专门为Pastebin完成的吗?据我所知,因为它并不能真正起作用。但是我猜你可以再用一个😉
Option Explicit
Private Declare PtrSafe Function URLDownloadToFileA Lib "URLMON" _
(ByVal pcaller As Long, _
ByVal szurl As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As LongPtr
Sub Example()
Dim Download$
On Error GoTo ErrorHandler
Download = URLDownloadToFileA(0, "myURL", "C:\Users\Name\Downloads\test.txt", 0, 0)
Exit Sub
ErrorHandler:
MsgBox Err.Number & " " & Err.Description
End Sub