VBA to save file as to a directory

sandra40s

New Member
Joined
Aug 31, 2005
Messages
28
I need help in creating a VBA to save file as to a directory. I have the old file names including the directory in Worksheet1. I have the new file names including the new directory in Worksheet2. There are over 200 that needs to be saved as with the new name and directory. Please help.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hello!
smt. like that?
Code:
Sub Savewb()
Set oldwbfullname = Sheets("Sheet1")
Set newwbfullname = Sheets("Sheet2")
lst = oldwbfullname.Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lst
FileCopy oldwnfullname.Cells(i, 1), newwbfullname.Cells(i, 1)
Next
Application.DisplayAlerts = True
End Sub

(here old names and new names considered to be at the same row)
 
Upvote 0
Useful,
I got an Object required (Error 424) when I used the code.

check your path is correct

(both old and new path & name begins from range A1. For ex: old - path&names starts from sheet1 range A1 (D:\path\oldname1.xlsx) and new - path&names (C:\path\newname1.xlsb) starts from sheet2 range A1)
 
Upvote 0
Hi
Should this
Code:
FileCopy [COLOR=#ff0000]oldwnfullname[/COLOR].Cells(i, 1), newwbfullname.Cells(i, 1)
be
Code:
FileCopy [COLOR=#ff0000]oldwbfullname[/COLOR].Cells(i, 1), newwbfullname.Cells(i, 1)
 
Upvote 0
This is an example of the file names. Sorry about using colors but this is the best I could do.

Old file name F:\Blue\Green\Red\2015 Orange Files\111 2015.xlsm
New file name F:\Blue\Purple\Yellow\Faded\Out\Out 2015\Colors 2015.xlsm
 
Upvote 0
Fluff,
FileCopy oldwbfullname.Cells(i, 1), newwbfullname.Cells(i, 1) seems to be more accurate in what I need to do. I will try it.
 
Upvote 0
Hi,
Yap, sorry, one letter was not correct ("n"). instead of oldwnfullname should be oldwbfullname or opposite. As you see above it decleared as "oldwnfullname" therefore you have to change either of them as the other one.
 
Upvote 0
I got a path not found. I know the path is correct because I copied it. Is this a save as VBA? Is there an easier way to do this like old and new file names on the same line?
 
Upvote 0

Forum statistics

Threads
1,214,999
Messages
6,122,645
Members
449,093
Latest member
Ahmad123098

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