通过 URLDownloadToFile 自动下载 PDF
Auto Download PDF thru URLDownloadToFile
如何从网站提取 PDF 的默认名称而不是以下代码中的 blah.pdf?
Option Explicit
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 z()
Dim strSource As String
Dim strDest As String
strSource = "http://www.cran.r-project.org/doc/manuals/R-intro.pdf"
strDest = "c:\temp\blah.pdf"
URLDownloadToFile 0, strSource, strDest, 0, 0
End Sub
用你原来的下载方法是可以的,但是你是怎么确定路径和文件名的呢?你有清单吗?需要从网站上获取吗?关于检索仪器编号,首先将引用(VBE > 工具 > 引用)设置为 Microsoft XML、vx.0 和 Microsoft HTML 对象库,然后相应地更改指定的 URL,然后尝试...
Option Explicit
Sub GetInstrumentNumber()
'Set a reference (VBE > Tools > References) to the following libraries:
' 1) Microsoft XML, v6.0 (or whatever version you have)
' 2) Microsoft HTML Object Library
Dim XMLReq As New MSXML2.XMLHTTP60
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim sURL As String
Dim sInstrument As String
sURL = "http://www.cran.r-project.org/..." 'change the URL adddress accordingly
With XMLReq
.Open "GET", sURL, False
.send
Do While .readyState <> 4
DoEvents
Loop
End With
If XMLReq.Status <> 200 Then
MsgBox "Error " & XMLReq.Status & ": " & XMLReq.statusText
Exit Sub
End If
HTMLDoc.body.innerHTML = XMLReq.responseText
sInstrument = HTMLDoc.getElementById("6063270").getElementsByTagName("tr")(0).Cells(0).innerText
sInstrument = Trim(Split(sInstrument, ":")(1))
MsgBox "Instrument number: " & sInstrument, vbInformation
Set XMLReq = Nothing
Set HTMLDoc = Nothing
End Sub
如何从网站提取 PDF 的默认名称而不是以下代码中的 blah.pdf?
Option Explicit
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 z()
Dim strSource As String
Dim strDest As String
strSource = "http://www.cran.r-project.org/doc/manuals/R-intro.pdf"
strDest = "c:\temp\blah.pdf"
URLDownloadToFile 0, strSource, strDest, 0, 0
End Sub
用你原来的下载方法是可以的,但是你是怎么确定路径和文件名的呢?你有清单吗?需要从网站上获取吗?关于检索仪器编号,首先将引用(VBE > 工具 > 引用)设置为 Microsoft XML、vx.0 和 Microsoft HTML 对象库,然后相应地更改指定的 URL,然后尝试...
Option Explicit
Sub GetInstrumentNumber()
'Set a reference (VBE > Tools > References) to the following libraries:
' 1) Microsoft XML, v6.0 (or whatever version you have)
' 2) Microsoft HTML Object Library
Dim XMLReq As New MSXML2.XMLHTTP60
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim sURL As String
Dim sInstrument As String
sURL = "http://www.cran.r-project.org/..." 'change the URL adddress accordingly
With XMLReq
.Open "GET", sURL, False
.send
Do While .readyState <> 4
DoEvents
Loop
End With
If XMLReq.Status <> 200 Then
MsgBox "Error " & XMLReq.Status & ": " & XMLReq.statusText
Exit Sub
End If
HTMLDoc.body.innerHTML = XMLReq.responseText
sInstrument = HTMLDoc.getElementById("6063270").getElementsByTagName("tr")(0).Cells(0).innerText
sInstrument = Trim(Split(sInstrument, ":")(1))
MsgBox "Instrument number: " & sInstrument, vbInformation
Set XMLReq = Nothing
Set HTMLDoc = Nothing
End Sub