View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JLatham JLatham is offline
external usenet poster
 
Posts: 3,365
Default Macro to move files gets an error if it already exists...

Or you could simply use
KILL NewFilePath
since you've already set that up in your code. Got in too big of a rush to
copy. So

Function TXTFileMove()

OldFilePath = "C:\Import Files\New\" & TXTFileName
NewFilePath = C"\Import Files\Complete\" & TXTFileName
On Error Resume Next
KILL NewFilePath
If ERR<0 Then
ERR.CLEAR
End If
On Error Goto 0
Name OldFilePath As NewFilePath

End Function
" wrote:

Hello all,

I have the following macro snippet that moves a txt file AFTER its
data has been imported into a spreadsheet. It works great as long as
the file doesn't already exist.

Function TXTFileMove()

OldFilePath = "C:\Import Files\New\" & TXTFileName
NewFilePath = C"\Import Files\Complete\" & TXTFileName
Name OldFilePath As NewFilePath

End Function

If the file already exists in that location, the macro halts with the
error:

Run-time error '58': File already exists [End] [Debug]

I've tried enclosing the "path" commands with
Application.DisplayAlerts = False, but it didn't work.