开发者

Difficulites in accessing the Download files dialog box - VBA Code

I have mini project in VBA (Excel). I need to open the IE and download the files (save the doc) in the designated folder in my desktop.

However, I having difficulties in accessing the Download files dialog box. Even tried Savekeys concept but in vain.

How to proceed further and save the files?

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 DownloadFileFromWeb()
    Dim myFile As String
    Dim strSavePath As String
    Dim URL As String, ext As String

    URL = "www.ahma.org/Education/BRD_Hardlines_Industry_Item.doc" 'for TEST
    strSavePath = "C:\Users\Yogendra.Ur\Desktop\" & "DownloadedFile" & ext

    Dim buf, Ret As Long
    buf = Split(URL, ".")
    ext = buf(UBound(buf))

    Dim IE As Object
    Set IE = CreateObject("internetexplorer.application")
    IE.VISIBLE = True
    IE.Navigate URL

    Ret = URLDownloadToFile(0, URL, strSavePath, 0, 0)

    If Ret = 0 Then
        MsgBox "Download has been succeed!"
 开发者_开发百科   Else
        MsgBox "Error"
    End If
End Sub


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 DownloadFileFromWeb()

    Dim myFile As String
    Dim buf, Ret As Long
    Dim strSavePath As String
    Dim URL As String, ext As String

    URL = "http://www.ahma.org/Education/BRD_Hardlines_Industry_Item.doc"         
    buf = Split(URL, ".")
    ext = buf(UBound(buf))

    strSavePath = "C:\local files\DownloadedFile." & ext
    Debug.Print strSavePath

    Ret = URLDownloadToFile(0, URL, strSavePath, 0, 0)

    If Ret = 0 Then
        MsgBox "Download OK!"
    Else
        MsgBox "Error"
    End If

End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜