Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy files based on excel value 1

Status
Not open for further replies.

Nogi

Technical User
Dec 10, 2004
132
BE
I'm a total newbie when it concerns VBA coding, so maybe one of you could help me out getting this script on the right track.
I have found the following code:

Code:
Sub Rectangle1_Click() 
    Dim n1 As String 
    Dim n2 As String 
    p = "C:\Documents and Settings\Desktop\" 
    n1 = p & "\" & "testdoc.doc" 
    n2 = p & "\" & "testdoc2.doc" 
    a = MoveFile(n1, n2) 
End Sub 
 
Function MoveFile(AFileName As String, aDestinationName As String) 
     'Note - Include full paths above
    If AFileName = "" Then Exit Function 
     'If testforfile(AFileName) < 1 Then Exit Function: ' this is a custom function to test if the file exists
    Set fs = CreateObject("Scripting.FileSystemObject") 
    Set f = fs.getfile(AFileName) 
    f.Copy aDestinationName 
     ' f.Delete: 'optional step
    fs = "" 
    f = "" 
End Function

What it does is copy a file from one location to another.

In my particular situation, i have an excelfile in which column B contains the names of folders.
The folders themselfs exist on a network location.

What i would like to accomplish is, that with a click on a button, the script reads all foldernames of Column B, and copies their corresponding folders on the network to the path of the excelfile.

So as example:
Cell B1= "S0003344", B2="S0007070", B3="S050505" etc.
With a click on a button, the script goes to the networklocation (//mynetwork/folders) and copies all folders of which the names are in the excel column, to the path of the excelfile.

Is there somebody who thinks he can help me out with this?

Thanks in advance
 
This might help you get going...
Code:
Sub CopyAllInRange2005()
    Dim MyPath As String, MyName As String
    MyPath = Path ' You'll want to change this!
    For Each c In Range("B4:B56")'set this to your range
        FileCopy MyPath & "\Template.xls", MyPath & "\" & c.Value & ".xls"
    Next
    MsgBox "All Done!"
End Sub
 
Hey thanks alot for your great help comaboy. Highly appriciated, and most of all, working! yeay!

again, thanks for your effords & time,

Nogi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top