Saturday, April 20, 2019

Move Folder From One Location to Another in Excel VBA

Move Folder From One Location to Another in Excel VBA

'In this Example I am Moving "C:\Temp\" to "D:\Job\"
Sub sbMovingAFolder()

Dim FSO
Dim sFolder As String, dFolder As String

sFolder = "C:\Temp\" 'Specify Your Source Folder
dFolder = "D:\Job\" ' Specify Your Destination Folder
Set FSO = CreateObject("Scripting.FileSystemObject")

If Not FSO.FolderExists(dFolder) Then
FSO.MoveFolder sFolder, 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 Sub

No comments:

Post a Comment