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
Private Sub Command1_Click()
Dim ret As Long
ret = URLDownloadToFile(0, Url, SavePath, 0, 0)
If ret = 0 Then
MsgBox "下载成功¦"
Else
MsgBox "下载失败!"
End If
Public Function DownLoad(ByVal Url As String, ByVal SavePath) As String
On Error Resume Next
Dim Dl As String
Dl = Url
Dim str As String
str = "Microsoft.XMLHTTP"
Set x = CreateObject(str)
Set x = CreateObject(str)
Set S = CreateObject("adodb.stream")
S.Type = 1
x.open "GET", Dl, False
x.Send
Fname = SavePath
Set Fs = CreateObject("Scripting.FileSystemObject")
Set tmp = Fs.GetSpecialFolder(2) '缓存
Fname = Fs.BuildPath(Fname)
S.open
S.write x.responseBody
S.SaveToFile Fname, 2
MsgBox ("文件已经下至" + Fname)
S.Close
Dim list() As String
list = Split(Fname, "\")
DownLoad = list(UBound(list))
End Function
Public Sub OpenFile()
Set Q = CreateObject("Shell.Application")
Q.ShellExecute Fname
End Sub