The following macro works for me :
Code:
Sub CopyOrMoveFiles()
Dim fd As fileDialog
Dim selectedItems As FileDialogSelectedItems
Dim selectedFile As Variant
Dim destinationPath As String
Dim userChoice As Integer
Dim fso As Object
' Initialize FileDialog
Set fd = Application.fileDialog(msoFileDialogFilePicker)
fd.AllowMultiSelect = True
fd.Title = "Select Files to Copy or Move"
' Show the FileDialog
If fd.Show = -1 Then
Set selectedItems = fd.selectedItems
Else
MsgBox "No files were selected."
Exit Sub
End If
' Ask user for destination folder
Set fd = Application.fileDialog(msoFileDialogFolderPicker)
fd.Title = "Select Destination Folder"
If fd.Show = -1 Then
destinationPath = fd.selectedItems(1) & "\"
Else
MsgBox "No destination folder was selected."
Exit Sub
End If
' Ask user whether to copy or move files
userChoice = MsgBox("Do you want to copy the files? Click 'No' to move them.", vbYesNoCancel + vbQuestion, "Copy or Move Files")
If userChoice = vbCancel Then
MsgBox "Operation cancelled."
Exit Sub
End If
' Initialize FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Copy or move files based on user choice
For Each selectedFile In selectedItems
If userChoice = vbYes Then
' Copy files
fso.CopyFile Source:=selectedFile, Destination:=destinationPath, OverWriteFiles:=True
Else
' Move files
End If
Next selectedFile
MsgBox "Files have been successfully processed."
End Sub