VBA Save File From Link as same extension

Guna13

Board Regular
Joined
Nov 22, 2019
Messages
70
Office Version
  1. 365
Platform
  1. Windows
Hi Team

I wonder whether someone can help me, please.

Hyperlink had different type of extention like .xlsx. xls, pdf, .msg documents, all document should download and saveas in folder same extention

Could someone possible tell me please is there a way by which I can amend the code.

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


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

1595860868638.png
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
currently, this code is running, but there is no document save in that folder ...:oops::(
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top