Move then overwrite existing file

DougRobertson

Active Member
Joined
Sep 22, 2009
Messages
334
Office Version
  1. 365
Platform
  1. Windows
Okay, I'm skunked!

I've tried the following code to MOVE an Excel file, and it works well:

Name "C:\FILE.xlsx" As "C:\FOLDER 1\FILE.xlsx"

However if a file by that name already exist there, I get an error. If I precede that code with:

Application.DisplayAlerts = False

it still won't let me OVERWRITE the old file.

Thanks for the help,

~ Doug
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try...

Code:
[font=Verdana]    [color=darkblue]Dim[/color] OldPathName [color=darkblue]As[/color] [color=darkblue]String[/color]
    [color=darkblue]Dim[/color] NewPathName [color=darkblue]As[/color] [color=darkblue]String[/color]
    
    OldPathName = "C:\FILE.xlsx"
    
    NewPathName = "C:\FOLDER 1\FILE.xlsx"
    
    [color=darkblue]If[/color] Dir(NewPathName) <> "" [color=darkblue]Then[/color]
        Kill NewPathName
        Name OldPathName [color=darkblue]As[/color] NewPathName
    [color=darkblue]Else[/color]
        Name OldPathName [color=darkblue]As[/color] NewPathName
    [color=darkblue]End[/color] [color=darkblue]If[/color]
[/font]
 
Upvote 0
Is there a way to do this but with using the current file path of the XLS file.

so have it copy/move from \newinfo.csv to \output\newinfo.csv
 
Upvote 0
If you mean the path of the workbook in which the code is being run, then try...

Code:
NewPathName = ThisWorkbook.Path & "\" & "newinfo.csv"
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,777
Members
452,942
Latest member
VijayNewtoExcel

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