|
-
September 28th, 2011, 08:31 PM
#1
VB.NET copy files from excel column?
I have many files at work that need to be copied from one directory to another. However, I do not need to copy all the files at once.
I get excel sheets with the list of files that need to be copied once a week. So, in the main directory there is about 150.000 files and I only need to copy about 800 at a time.
I need help doing this. I am thinking of having a textbox and an open dialog so I can pick the directory the main files are at - another one where I can choose where they will be copied to.
The problem is the list will be in excel sheet (column A). How do I have vb.net (2008) see the file names in column A and find them and move them?
Right now, I have macros in excel doing the job, however, I have so many things in this excel I need to transfer this part out and into vb.net.
The macro in excel doing the job is:
Code:
Sub CopyFiles()
Dim objFSO As FileSystemObject
Dim strSourceFolder As String
Dim strDestFolder As String
Dim arrMyFiles() As String
Dim MatchVal As Variant
Dim Cnt As Long
Dim i As Long
Dim LastRow As Long
Application.ScreenUpdating = False
Set objFSO = CreateObject("Scripting.FileSystemObject")
'*****************************************************************
'*****************************************************************
'---- This is the only part that you need to change ----
'*****************************************************************
'Change the path to the source folder accordingly
strSourceFolder = "C:\Users\dbush\Desktop\test\"
'Change the path to the destination folder accordingly
strDestFolder = "C:\Users\dbush\Desktop\teest\"
'*****************************************************************
'*****************************************************************
Call ProcessFolders(objFSO, strSourceFolder, arrMyFiles(), Cnt)
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To LastRow
With Application
MatchVal = .Match(Cells(i, "A").Value, .Index(arrMyFiles, 2, 0), 0)
'Error's found then put the value specified
If IsError(MatchVal) Then
'Cells(i, "B").Value = 1
Cells(i, "B").Value = ("Not Found")
'Colors the non-found cell yellow
Cells(i, "A").Interior.ColorIndex = 6
Else
'Add "Duplicate" to already found files
If objFSO.FileExists(strDestFolder & Cells(i, "A").Value) Then
Cells(i, "C").Value = "Duplicate"
Else
objFSO.GetFile(.Index(arrMyFiles, 1, MatchVal) & "\" & .Index(arrMyFiles, 2, MatchVal)).Copy strDestFolder, False
End If
'objFSO.GetFile(.Index(arrMyFiles, 1, MatchVal) & "\" & .Index(arrMyFiles, 2, MatchVal)).Copy strDestFolder
End If
End With
Next i
Application.ScreenUpdating = True
'Message box when finished
MsgBox "Dave's Program has Completed...", vbInformation
Can someone please help me with this changing it over to vb.net?
Any help will be very much appreciated.
daveofgv
Last edited by daveofgv; September 28th, 2011 at 08:45 PM.
-
September 29th, 2011, 04:13 PM
#2
Re: VB.NET copy files from excel column?
Here's a link, to download SAMPLE files
-
September 29th, 2011, 04:38 PM
#3
Re: VB.NET copy files from excel column?
The link said 0 sample files found
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|