Downloading Videos from Link and save it to the folder created from the same link

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Yes, it is possible to download video files from URLs and save them to specific folders with dynamically generated names. Here's an example of how you can achieve this using VBA in Excel:

VBA Code:
Sub DownloadAndSaveVideo()
    Dim url As String
    Dim folderName As String
    Dim folderPath As String
    Dim videoPath As String
    
    ' URL of the video
    url = "https://dna1.braintreeeasysoft.com/533286666/533286666.html"
    
    ' Extract the folder name from the URL
    folderName = Split(Split(url, "/")(3), ".")(0)
    
    ' Set the folder path where the video will be saved
    folderPath = "C:\Path\To\Your\Folder\" & folderName
    
    ' Create the folder if it doesn't exist
    If Dir(folderPath, vbDirectory) = "" Then
        MkDir folderPath
    End If
    
    ' Set the video file path
    videoPath = folderPath & "\" & folderName & ".mp4"
    
    ' Download the video
    URLDownloadToFile 0, url, videoPath, 0, 0
    
    ' Display a message with the saved video path
    MsgBox "Video downloaded and saved to: " & videoPath
End Sub

In the above code, you need to replace "https://dna1.braintreeeasysoft.com/533286666/533286666.html" with the actual URL of the video you want to download. The code extracts the folder name from the URL and creates a folder with that name in the specified folder path. Then, it constructs the video file path using the folder name and saves the video using the URLDownloadToFile function. Finally, a message box displays the path where the video has been saved.

Make sure to modify the folderPath variable to the desired location where you want the folders to be created and videos to be saved.

Note that the URLDownloadToFile function requires the urlmon library to be referenced in your VBA project. You can add the reference by going to the Visual Basic Editor (Alt+F11), selecting "Tools" from the menu, choosing "References," and then checking the box for "Microsoft URL Moniker Control" in the list.

Remember to customize the code according to your specific requirements and incorporate it into your existing VBA macro as needed.
 
Upvote 0
Hey,
Thanks for your quick reposnse.
When am running i getting below error.

1684831316683.png



Also i have list of urls written in excel. Do i need to put all urls in this code ? or i need to keep in excel?
 
Upvote 0
Yes, it is possible to download video files from URLs and save them to specific folders with dynamically generated names. Here's an example of how you can achieve this using VBA in Excel:

VBA Code:
Sub DownloadAndSaveVideo()
    Dim url As String
    Dim folderName As String
    Dim folderPath As String
    Dim videoPath As String
   
    ' URL of the video
    url = "https://dna1.braintreeeasysoft.com/533286666/533286666.html"
   
    ' Extract the folder name from the URL
    folderName = Split(Split(url, "/")(3), ".")(0)
   
    ' Set the folder path where the video will be saved
    folderPath = "C:\Path\To\Your\Folder\" & folderName
   
    ' Create the folder if it doesn't exist
    If Dir(folderPath, vbDirectory) = "" Then
        MkDir folderPath
    End If
   
    ' Set the video file path
    videoPath = folderPath & "\" & folderName & ".mp4"
   
    ' Download the video
    URLDownloadToFile 0, url, videoPath, 0, 0
   
    ' Display a message with the saved video path
    MsgBox "Video downloaded and saved to: " & videoPath
End Sub

In the above code, you need to replace "https://dna1.braintreeeasysoft.com/533286666/533286666.html" with the actual URL of the video you want to download. The code extracts the folder name from the URL and creates a folder with that name in the specified folder path. Then, it constructs the video file path using the folder name and saves the video using the URLDownloadToFile function. Finally, a message box displays the path where the video has been saved.

Make sure to modify the folderPath variable to the desired location where you want the folders to be created and videos to be saved.

Note that the URLDownloadToFile function requires the urlmon library to be referenced in your VBA project. You can add the reference by going to the Visual Basic Editor (Alt+F11), selecting "Tools" from the menu, choosing "References," and then checking the box for "Microsoft URL Moniker Control" in the list.

Remember to customize the code according to your specific requirements and incorporate it into your existing VBA macro as needed.
I am not able to find the option under references- "Microsoft URL Moniker Control" is this because i have to download any new tools?
 
Upvote 0
Upvote 0
When am running i getting below error.

Think you need to place the below code above the Sub line (above the code):
VBA Code:
Private Declare PtrSafe 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

If you go back to the original format with the URL's in post 1. Put those values in column A starting at row 2, adjust the folderPath to suit where you want the files to be saved and then try running the below:
VBA Code:
Option Explicit

Private Declare PtrSafe 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 DownloadAndSaveVideo()
    Dim url As String
    Dim folderName As String
    Dim folderPath As String
    Dim videoPath As String
    Dim rCell As Range
    
    For Each rCell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
        url = rCell.Value ' URL of the video
        folderName = Split(Split(url, "/")(3), ".")(0) ' Extract the folder name from the URL
        folderPath = "C:\Users\jbloggs\Desktop\TEST\" & folderName ' Set the folder path where the video will be saved
        If Dir(folderPath, vbDirectory) = "" Then ' Create the folder if it doesn't exist
            MkDir folderPath
        End If
        videoPath = folderPath & "\" & folderName & ".mp4" ' Set the video file path
        URLDownloadToFile 0, url, videoPath, 0, 0 ' Download the video
    Next rCell
    
    MsgBox "Video(s) downloaded and saved" ' Display a message with the saved video path
End Sub
 
Upvote 0
Think you need to place the below code above the Sub line (above the code):
VBA Code:
Private Declare PtrSafe 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

If you go back to the original format with the URL's in post 1. Put those values in column A starting at row 2, adjust the folderPath to suit where you want the files to be saved and then try running the below:
VBA Code:
Option Explicit

Private Declare PtrSafe 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 DownloadAndSaveVideo()
    Dim url As String
    Dim folderName As String
    Dim folderPath As String
    Dim videoPath As String
    Dim rCell As Range
   
    For Each rCell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
        url = rCell.Value ' URL of the video
        folderName = Split(Split(url, "/")(3), ".")(0) ' Extract the folder name from the URL
        folderPath = "C:\Users\jbloggs\Desktop\TEST\" & folderName ' Set the folder path where the video will be saved
        If Dir(folderPath, vbDirectory) = "" Then ' Create the folder if it doesn't exist
            MkDir folderPath
        End If
        videoPath = folderPath & "\" & folderName & ".mp4" ' Set the video file path
        URLDownloadToFile 0, url, videoPath, 0, 0 ' Download the video
    Next rCell
   
    MsgBox "Video(s) downloaded and saved" ' Display a message with the saved video path
End Sub
Hey Thanks for your quick Help- yes now code the is running by adding the above sub-line.
2nd requirement was there is change in format of link now and once we able to download video from the link- video folder need to be saved into new folder mentioned in column B.
VIDEO URLCert No
566305442
551212407
551212206
550225080
551212964
566328502
 
Upvote 0
I was hoping you would have a go at sorting that part out yourself:

VBA Code:
Option Explicit

Private Declare PtrSafe 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 DownloadAndSaveVideo()
    Dim url As String
    Dim folderName As String
    Dim folderPath As String
    Dim videoPath As String
    Dim rCell As Range
  
    For Each rCell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
        url = rCell.Hyperlinks(1).Address ' URL of the video
        folderName = rCell.Offset(, 1)
        folderPath = "C:\Users\jbloggs\Desktop\TEST\" & folderName ' Set the folder path where the video will be saved
        If Dir(folderPath, vbDirectory) = "" Then ' Create the folder if it doesn't exist
            MkDir folderPath
        End If
        videoPath = folderPath & "\" & folderName & ".mp4" ' Set the video file path
        URLDownloadToFile 0, url, videoPath, 0, 0 ' Download the video
    Next rCell
  
    MsgBox "Video(s) downloaded and saved" ' Display a message with the saved video path
End Sub

Not sure what the actual file name was to be so I went with: folderName
 
Upvote 0
I was hoping you would have a go at sorting that part out yourself:

VBA Code:
Option Explicit

Private Declare PtrSafe 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 DownloadAndSaveVideo()
    Dim url As String
    Dim folderName As String
    Dim folderPath As String
    Dim videoPath As String
    Dim rCell As Range
 
    For Each rCell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
        url = rCell.Hyperlinks(1).Address ' URL of the video
        folderName = rCell.Offset(, 1)
        folderPath = "C:\Users\jbloggs\Desktop\TEST\" & folderName ' Set the folder path where the video will be saved
        If Dir(folderPath, vbDirectory) = "" Then ' Create the folder if it doesn't exist
            MkDir folderPath
        End If
        videoPath = folderPath & "\" & folderName & ".mp4" ' Set the video file path
        URLDownloadToFile 0, url, videoPath, 0, 0 ' Download the video
    Next rCell
 
    MsgBox "Video(s) downloaded and saved" ' Display a message with the saved video path
End Sub

Not sure what the actual file name was to be so I went with: folderName
Hi,

Links are like this
"V360 Viewer"
So when am running the code its showing error in this field.
 
Upvote 0

Forum statistics

Threads
1,216,094
Messages
6,128,785
Members
449,468
Latest member
AGreen17

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