Download File

Private Declare Function DoFileDownload Lib “shdocvw.dll” (ByVal lpszFile As String) As Long
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()

End Sub

Private Sub cmdMethod1_Click()
Dim thePath As String

thePath = InputBox(“What is the url to download the file?”, ” File Url”, “http://”)

‘The path has to be converted to Unicode
thePath = StrConv(thePath, vbUnicode)

DoFileDownload thePath
End Sub

Private Sub Command2_Click()

End Sub

Private Sub cmdMethod2_Click()
Dim retVal As Long ‘our return value
Dim theUrl As String ‘the url you want to download
Dim savePath As String ‘where you want to save the url
Dim pathExist As Long ‘will contain our path exist or not value

theUrl = InputBox(“What is the url you want to download?”, ” Url Path?”, “http://”)
If theUrl = “” Then Exit Sub

savePath = InputBox(“What is the path and filename to save the url to?”, ” Path and Filename to save”)
If savePath = “” Then Exit Sub

retVal = URLDownloadToFile(0, theUrl, savePath, 0, 0)

If retVal = 0 Then
MsgBox “File was downloaded successfully!”, vbExclamation, ” Download Successful”
MsgBox “There was a error downloading the file. Make sure that the url is valid and try again!”, vbCritical, ” Error”
End If
End Sub


One response to “Download File

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s