View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rookie_User Rookie_User is offline
external usenet poster
 
Posts: 78
Default Move and delete files

I inserted the full path in column A and was getting it closer but it errors
by saying a file already exists when it attempts the move? I put watches on
the values and the destination is accurate and the file does not exist there,
any idea's?

"Jeff" wrote:

Try this

Public Sub MoveFiles(ByVal Source As String, ByVal Destination As String)
Dim oFSO As Object


Set oFSO = CreateObject("Scripting.FileSystemObject")

With oFSO
If .FileExists(Source) Then
.MoveFile Source, Destination
Else
MsgBox Source & " Doesn't Exist", vbExclamation
End If
End With
Set oFSO = Nothing
End Sub

Sub RunThroughList()
Dim I As Long
Dim Destination As String
Dim Lastrow As Long

Lastrow = Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row

For I = 1 To Lastrow
MoveFiles Range("A" & I).Value, "C:\Documents and Settings\My Documents\"

Next
End Sub




"Rookie_User" wrote:

I would like to cascade down through my worksheet from top to the end and
process the data as follows. In column A I have a filename, I will have a
constant source folder identified (ie. c:\input) and target folder identified
(ie. c:\output).

Column A
test1.txt
test2.txt
test3.txt

I would like to verify the file actually exists and IF it does then move it
to the destination folder and delete the file. If the file does NOT exist
then possibly highlight that cell so it can be removed from the worksheet.

I had a function that checks the file but all UDF are no longer working. I
use Excel 2007. Any help would be appreciated.