Monday, October 22, 2012

How To Copy a File From One Path to Another Path

Excel VBA Macro To Copy  a File From One Path to Another Path
Sub Copy_All_Folder_Files()
Dim SourceFolderPath As String
Dim TargetFolderPath As String
Dim FSO As Object

SourceFolderPath = "C:\Documents and Settings\Administrator\My Documents\SourceFolder"

'File Path Should Specify Exactly
'TargetFolderPath = "C:\Documents and Settings\Administrator\My Documents"
TargetFolderPath = "F:\TargetFolder"

If Right(SourceFolderPath, 1) = "\" Then
SourceFolderPath = Left(SourceFolderPath, Len(SourceFolderPath) - 1)
End If

'If Right(TargetFolderPath, 1) = "\" Then
'TargetFolderPath = Left(TargetFolderPath, Len(TargetFolderPath) - 1)
'End If

Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FolderExists(SourceFolderPath) = False Then
MsgBox ("Source Folder Does Not Exist or Path Not Found")
End If

If FSO.FolderExists(TargetFolderPath) = False Then
MsgBox ("Target Folder Does Not Exist or Path Not Found")
End If

On Error Resume Next
FSO.CopyFolder SourceFolderPath, TargetFolderPath
MsgBox "SuccessFull Copied"

End Sub

Thanks,Tamatam

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog