View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Matthew Herbert[_3_] Matthew Herbert[_3_] is offline
external usenet poster
 
Posts: 149
Default Error 58, file already exists - why?

Rookie_User,

Are your names fully qualified? For example, you need to use
C:\MoveFrom\test.txt rather than test.txt.

Have you looked over the help documentation for MoveFile Method (i.e. you
know how source should be set up and you know the implications of leaving off
"\" for destination)? Also, you may want to consider the Name Statement (see
the VBE Help files for this).

Without me creating any code to mirror what you are doing, I would start by
examining the help documentation and ensure that your arguments are correct.

Best,

Matthew Herbert

"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