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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script copy files excel value - adjusting script

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
 
Please read faq222-2244 to find out how to get the best from these forums, particularly on how to find the appropriate forum. For VBA questions use forum707

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top