06-12-2013, 02:08 PM
Thats because there is no error encountered and hence the IF loop is not satisfied. Only on an error would the err.number will bring up an error number and traverse into the loop. When there was no error encountered it skipped the If loop and went to the next line. However the copy has already happened outside of the loop and hence you see that behaviour.
You have to use an Else to skip the If condition and put up your msgbox there.
you could see that the folder is not copied if you try this code below,
You have to use an Else to skip the If condition and put up your msgbox there.
Code:
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
FSO.CopyFolder "C:\Program Files\Test", "E:\Test"
If err.number <> 0 Then
FSO.CreateFolder "E:\Test"
FSO.CopyFolder "C:\Program Files\Test", "E:\Test"
Else
MsgBox "Folder Copied"
End If
you could see that the folder is not copied if you try this code below,
Code:
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If err.number <> 0 Then
FSO.CreateFolder "E:\Test"
FSO.CopyFolder "C:\Program Files\Test", "E:\Test"
msgbox "Files Copied"
End If
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.