PDA

View Full Version : Copy files, from a given list!



Londonoffice
09-10-2010, 05:25 AM
Hi,

this is my first message, I found a macro that looks powerful even if I didn't try it out it seems to be very close to a tool I need.
The macro I saw is:

*ttp://*ww.vbaexpress.com/kb/getarticle.php?kb_id=827 It appears that this macro copies all the files from a folder to another, and considers different type of errors.
What I need is, not to copy all the files, but those listed in a column in excel.
I don't know anything about programming, but someone kindly wrote for me a macro that does the trick. However, that doesn't consider the case the files already exist in the destination folder, or the files listed in the list are not present in the source folder.
I have no idea on how to modify it but it would be of great help if you could help me to modify this macro so that not all the content of a folder, but only the files specified in a list like in the macro below are subject to copy to another folder. It would be just perfect if I then could run the macro with a hotkey!

Sub CopiaLista()
Dim InitialFoldr$
InitialFoldr$ = "L:\source\"
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Please select a folder to copy Files from"
.InitialFileName = InitialFoldr$
.Show
PercCorr = .SelectedItems(1) & "\"
End With

With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to copy Files to"
.InitialFileName = InitialFoldr$
.Show
PercNew = .SelectedItems(1) & "\"
End With

For I = 2 To Cells(Rows.Count, 1).End(xlUp).Row 'Elenco file da A2 verso il basso
NomeFile = PercCorr & Cells(I, 1).Value
'Name NomeFile As Replace(NomeFile, PercCorr, PercNew)
FileCopy NomeFile, Replace(NomeFile, PercCorr, PercNew)
Next I

End Sub

Kenneth Hobs
09-10-2010, 04:03 PM
See if you can adapt what I explained in this thread. http://www.vbaexpress.com/forum/showthread.php?t=26541