Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Only moves one file to destination folder

Status
Not open for further replies.

hsingh1981

Programmer
Apr 8, 2008
56
GB
Hi all i found code on this site which moves all files with a paticular extension. (faq707-4116)

However i made some very little alterations so it moves all .mdi files. But it only moves just one file to the destination folder. Not sure where i've gone wrong?

Code:
Sub MoveFilesFolder2Folder()
Dim fso

   'source folder path
   sfol = "Y:\DischargeLetters"
   
   'destination folder path
   dfol = "Y:\DischargeLetters\EmailSent"

Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If Not fso.FolderExists(sfol) Then
    MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid Source"
ElseIf Not fso.FolderExists(dfol) Then
    MsgBox dfol & " is not a valid folder/path.", vbInformation, "Invalid Destination"
Else
    fso.MoveFile (sfol & "\*.mdi*"), dfol ' Change "\*.*" to "\*.mdi" to move mdi Files only
End If
If Err.Number = 53 Then MsgBox "File not found"
End Sub
 
Found out that one of the mdi files was open on another computer and was readonly. Soon as i closed that it worked.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top