元のファイルが破損しないように、ソース フォルダーにファイルをプルし、自分のフォルダーに移動して分析する VBA コードを作成しています。しかし、名前が同じであることが検出された場合に古いファイルを置き換えるコードを書くのは困難です。
Private Sub CommandButton1_Click()
Dim FSO
Dim sFile As String
Dim sSFolder As String
Dim sDFolder As String
Dim datasource As Workbook
Dim target As Worksheet
Dim strName As String
Dim lastrow As Long
Dim userinput As String
userinput = InputBox(Prompt:="Please key in the file name and format", Title:=" File name", Default:=".xlsm") 'This is Your File Name which you want to Copy
sSFolder = "J:\Inter Dept\MP8 Packaging\2.0 MP8.1\B2-Machine Data Tracking\B2-Machine Data Tracking 2019\" 'Change to match the source folder path
sDFolder = "C:\Users\limmigmy\Desktop\Rejection Report\Rejection\Packing Analysis\Production Files\" 'Change to match the destination folder path
Set FSO = CreateObject("Scripting.FileSystemObject") 'Create Object
If Not FSO.FileExists(sSFolder & userinput) Then 'Checking If File Is Located in the Source Folder
MsgBox "Specified File Not Found", vbInformation, "Not Found"
ElseIf Not FSO.FileExists(sDFolder & userinput) Then 'Copying If the Same File is Not Located in the Destination Folder
FSO.CopyFile (sSFolder & sFile), sDFolder, True
MsgBox "Specified File Copied Successfully", vbInformation, "Done!"
**Else
MsgBox "Specified File Already Exists In The Destination Folder",** vbExclamation, "File Already Exists"
End If