Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-06-2025, 07:51 PM
Logit Logit is offline Copy or Move Files Windows 10 Copy or Move Files Office 2007
Expert
Copy or Move Files
 
Join Date: Jan 2017
Posts: 587
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default


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
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Dragging a selection to copy it, not to move it wardw Word VBA 2 11-28-2019 11:09 AM
VBA Word - Search Within Files Containing A String - Copy Files to New Folder jc491 Word VBA 0 01-09-2016 12:00 PM
Copy or Move Files copy and move not working inventorgeorge Word 8 07-09-2012 03:59 PM
Hyperlink i Word: Copy-paste, and move eradem Word 0 10-01-2011 03:50 AM
Copy or Move Files don't move/copy...., where? Yumin Word 1 04-04-2010 08:22 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft