Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi Team

I wonder whether someone can help me.

Hyperlink had a different type of extension like .xlsx. xls, pdf, .msg documents, all document should download and save in a create folder as the same Extention Type

Could someone possibly tell me please is there a way by which I can amend the code. this code is work as if document as .xlsx, but Other Extention not able to download through macro

To help this is the code that I use to create the list of files.

What I have tried:

VB
Option Explicit

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

Dim Ret As Long

'~~> This is where the images will be saved. Change as applicable
Const ParentFolderName As String = "\\gssux002\GBS_CHE_GL_TMS\ICV\"
Sub Download_Report()
Dim ws As Worksheet
Dim LastRow As Long, i As Long
Dim Folderpath, strPath As String

Set ws = Sheets("ICV Report")

LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row

For i = 2 To LastRow

Folderpath = ParentFolderName & ws.Range("A" & i).Value & "\"

If Len(Dir(Folderpath, vbDirectory)) = 0 Then
MkDir Folderpath
End If

strPath = Folderpath & ws.Range("A" & i).Value & i & "*.*"
Ret = URLDownloadToFile(0, ws.Range("H" & i).Value, strPath, 0, 0)

If Ret = 0 Then
ws.Range("I" & i).Value = "File successfully downloaded"
Else
ws.Range("I" & i).Value = "Unable to download the file"
End If

Next i

MsgBox "Completed This process !!!", vbInformation

End Sub[/CODE]
Posted
Updated 27-Jul-20 22:31pm
v2
Comments
Richard MacCutchan 28-Jul-20 4:33am    
That code is specific to Excel. for other file types you need to use binary stream readers.
Member 14784416 28-Jul-20 5:03am    
can you help me what is binary stream readers? is there any possible to download other extension documents from the excel hyperlink.
Member 14784416 28-Jul-20 5:48am    
Hi Richard thanks for your information, but honestly am not understanding this code. am from a finance background team and not much knowledge in code. so I took, my code is not worth to download documents from the hyperlink
Richard MacCutchan 28-Jul-20 5:50am    
Sorry, but there is not space here to teach you programming. You need to consider employing someone to do what you want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900