Hi, I have a macro I am working on and would like to get some help. I am trying to copy files from one folder to another folder based on a partial file name.
Here is the code I am currently using. It copies the entire contents of the folder (not what I want).
Here is the code I am currently using. It copies the entire contents of the folder (not what I want).
Code:
Private Sub CommandButton2_Click()
'copy files into folder
Dim FSO As Object
Dim sourcePath As String
Dim DestinationPath As String
Dim fileExtn As String
sourcePath = Sheet1.Cells(121, 9).Value
DestinationPath = Sheet1.Cells(110, 13).Value
fileExtn = "*.mpf"
If Right(sourcePath, 1) <> "\" Then
sourcePath = sourcePath & "\"
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.folderExists(sourcePath) = False Then
MsgBox sourcePath & "does not exist"
Exit Sub
End If
If FSO.folderExists(DestinationPath) = False Then
MsgBox DestinationPath & "does not exist"
Exit Sub
End If
FSO.copyfile Source:=sourcePath & fileExtn, Destination:=DestinationPath
MsgBox "Your files have been copied"
End Sub