View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
[email protected] gary@gcisecurityinc.com is offline
external usenet poster
 
Posts: 1
Default Error 58, file already exists - why?

On Monday, February 1, 2010 at 10:46:02 AM UTC-6, Rookie_User wrote:
I am trying to move a file from one folder to another - or at least copy and
delete the old file. I get an error 58 file already exists, and don't know
why?



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:\Output"

Next
End Sub