Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
CAM CAM is offline
external usenet poster
 
Posts: 9
Default Help!!! MoveFile Method

Hello,

Can someone see my code and try to help me get rid of this error message:
Run Time error '58';
File already exists

There will be existing files and I do want to overwrite those files
automatically and continue to move the rest of the files to the destination
folder.


Private Sub cmdMoveFiles_Click()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String

FromPath = "D:\Main Folder\"
FileExt = "*.xls"

If Right(FromPath, 1) < "\" Then
FromPath = FromPath & "\"
End If

FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "There is no files in " & FromPath Exit Sub
End If


Set FSO = CreateObject("scripting.filesystemobject")

ToPath = "D:\Test"

FSO.movefile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "Files moved from " & FromPath & " into " & ToPath

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Help!!! MoveFile Method

You might try copying the file to the destination,
with the "overwrite" argument set to True.
Then delete the original file.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"CAM"
wrote in message
Hello,
Can someone see my code and try to help me get rid of this error message:
Run Time error '58';
File already exists
There will be existing files and I do want to overwrite those files
automatically and continue to move the rest of the files to the destination
folder.

Private Sub cmdMoveFiles_Click()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String

FromPath = "D:\Main Folder\"
FileExt = "*.xls"

If Right(FromPath, 1) < "\" Then
FromPath = FromPath & "\"
End If

FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "There is no files in " & FromPath Exit Sub
End If

Set FSO = CreateObject("scripting.filesystemobject")
ToPath = "D:\Test"
FSO.movefile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "Files moved from " & FromPath & " into " & ToPath
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Help!!! MoveFile Method

Hi CAM

See the copy macro
http://www.rondebruin.nl/folder.htm

And then delete the files in frompath
http://www.rondebruin.nl/folder.htm#Delete


--
Regards Ron de Bruin
http://www.rondebruin.nl



"CAM" wrote in message ...
Hello,

Can someone see my code and try to help me get rid of this error message:
Run Time error '58';
File already exists

There will be existing files and I do want to overwrite those files automatically and continue to move the rest of the files to
the destination folder.


Private Sub cmdMoveFiles_Click()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String

FromPath = "D:\Main Folder\"
FileExt = "*.xls"

If Right(FromPath, 1) < "\" Then
FromPath = FromPath & "\"
End If

FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "There is no files in " & FromPath Exit Sub
End If


Set FSO = CreateObject("scripting.filesystemobject")

ToPath = "D:\Test"

FSO.movefile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "Files moved from " & FromPath & " into " & ToPath

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
CAM CAM is offline
external usenet poster
 
Posts: 9
Default Help!!! MoveFile Method

Ron,

I really appreciate you help and your excellent programing. Thanks again.
Regards,


"Ron de Bruin" wrote in message
...
Hi CAM

See the copy macro
http://www.rondebruin.nl/folder.htm

And then delete the files in frompath
http://www.rondebruin.nl/folder.htm#Delete


--
Regards Ron de Bruin
http://www.rondebruin.nl



"CAM" wrote in message
...
Hello,

Can someone see my code and try to help me get rid of this error message:
Run Time error '58';
File already exists

There will be existing files and I do want to overwrite those files
automatically and continue to move the rest of the files to the
destination folder.


Private Sub cmdMoveFiles_Click()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String

FromPath = "D:\Main Folder\"
FileExt = "*.xls"

If Right(FromPath, 1) < "\" Then
FromPath = FromPath & "\"
End If

FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "There is no files in " & FromPath Exit Sub
End If


Set FSO = CreateObject("scripting.filesystemobject")

ToPath = "D:\Test"

FSO.movefile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "Files moved from " & FromPath & " into " & ToPath

End Sub





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please post this thread a correct full method, method about Nast Runsome New Users to Excel 8 February 25th 08 03:29 PM
GetObject method not work after Call Shell Method ben Excel Programming 8 February 21st 06 03:45 PM
Movefile "Permission Denied" Gordon Gecko[_2_] Excel Programming 0 June 9th 05 08:44 PM
MoveFile problems [email protected] Excel Programming 1 December 28th 04 03:24 PM
How to maintain the original date and time for the MoveFile command Wellie Excel Programming 0 March 3rd 04 03:33 AM


All times are GMT +1. The time now is 01:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"