acerlaptop
New Member
- Joined
- Feb 17, 2020
- Messages
- 44
- Office Version
- 2013
- Platform
- Windows
Hi guys,
I have a code below that I'm currently working on. This code should move folder to another destination. But for some reason, the code moves the files inside the source folder, not the source folder itself.
Any thoughts please?
Thanks
I have a code below that I'm currently working on. This code should move folder to another destination. But for some reason, the code moves the files inside the source folder, not the source folder itself.
VBA Code:
Sub MOVE_FOLDER()
Dim FSO As Object
Dim sFolder As String, dFolder As String
sFolder = "H:\TEST\New folder\" & ActiveSheet.Range("D2").value
dFolder = "H:\TEST\New folder\" & ActiveSheet.Name
Set FSO = CreateObject("Scripting.FileSystemObject")
If Left(Right(sFolder, 7), 4) = ActiveSheet.Name Then
If Not FSO.FolderExists(dFolder) Then
FSO.MoveFolder Source:=sFolder, Destination:=dFolder
MsgBox "Folder Moved Successfully to The Destination", vbExclamation, "Done!"
Else
MsgBox "Folder Already Exists in the Destination", vbExclamation, "Folder Already Exists!"
End If
End If
End Sub
Any thoughts please?
Thanks