Overwrite Brower download file if exist

NileshAPatel

New Member
Joined
May 29, 2021
Messages
26
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi

I had written vba code to open multiple link from excel to browser "edge" which starts downloading excel file with dedicated name.

But wants code to overwrite file if already exist.

i.e once link open it started downloading file i.e. "CustomerOrderReport.xls" in folder "C:\Users\MIS\Downloads\"
but if same name file is already exist then it create new one with name "CustomerOrderReport (1).xls

I wants to overwrite file instead of creating new one.

Thanks in advance

Regards
Nilesh Patel
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Does the utility you use to download the file have a "overwrite" option?
Can you get the name of the file before downloading? If Yes then just Kill the file (use On Error Resume Next /GoTo 0 to skip exotic controls on the existance of the file)
Or you can download to a temporary directory, then your macro get the name of the file, kill the file in the final directory, move the file to the final directory. These final operations could be done using the following code:
VBA Code:
Dim TempPath As String, FinalPath As String, myF As String
'.
'Import your file to the Temp directory
'.
'.
TempPath = "C:\PROVA\TempPath\"           '<<< Your data
FinalPath = "C:\PROVA\FinalPath\"         '<<< Your data
'
myF = Dir(TempPath & "*.*")
If myF <> "" Then
    On Error Resume Next
        Kill FinalPath & myF
    On Error GoTo 0
    Application.Wait (Now + TimeValue("0:00:01"))
    Name (TempPath & myF) As FinalPath & myF
End If
Lines marked <<< need to be filled with YOUR data (and don't forget the final "\")
This assumes that the temporary path is initially empty
 
Upvote 0
Solution
Does the utility you use to download the file have a "overwrite" option?
Can you get the name of the file before downloading? If Yes then just Kill the file (use On Error Resume Next /GoTo 0 to skip exotic controls on the existance of the file)
Or you can download to a temporary directory, then your macro get the name of the file, kill the file in the final directory, move the file to the final directory. These final operations could be done using the following code:
VBA Code:
Dim TempPath As String, FinalPath As String, myF As String
'.
'Import your file to the Temp directory
'.
'.
TempPath = "C:\PROVA\TempPath\"           '<<< Your data
FinalPath = "C:\PROVA\FinalPath\"         '<<< Your data
'
myF = Dir(TempPath & "*.*")
If myF <> "" Then
    On Error Resume Next
        Kill FinalPath & myF
    On Error GoTo 0
    Application.Wait (Now + TimeValue("0:00:01"))
    Name (TempPath & myF) As FinalPath & myF
End If
Lines marked <<< need to be filled with YOUR data (and don't forget the final "\")
This assumes that the temporary path is initially empty
Thanks it solve my problem....
Thanks a lot again.
 
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

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