Hi there,
The code below is 90% working. The issue I am having is that the code move the 8 test files into the specified folder as expected. But does not write the file detail to the audit file as expected.
It appears that the code is overwriting line 1 and not append the data I have tried & vbNewLine and [FONT=SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace]& vbCrLf but i get the same results.[/FONT]
[FONT=SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace]I would expect to see 8 lines for each file that has been moved.[/FONT]
[FONT=SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace]Any help will be greatly appreciated.[/FONT]
The code below is 90% working. The issue I am having is that the code move the 8 test files into the specified folder as expected. But does not write the file detail to the audit file as expected.
It appears that the code is overwriting line 1 and not append the data I have tried & vbNewLine and [FONT=SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace]& vbCrLf but i get the same results.[/FONT]
[FONT=SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace]I would expect to see 8 lines for each file that has been moved.[/FONT]
[FONT=SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace]Any help will be greatly appreciated.[/FONT]
Code:
Sub Copy_Move_Files()
Dim fso As Object
Dim Cl As Range
Dim Fldr As String
Set fso = CreateObject("scripting.filesystemobject")
With Application.FileDialog(4)
.AllowMultiSelect = False
If .Show = -1 Then Fldr = .SelectedItems(1)
End With
For Each Cl In Range("A1", Range("A" & Rows.Count).End(xlUp))
If fso.FileExists(Cl.Value) Then
fso.CopyFile Cl.Value, Fldr & "\"
Call Write_file(Cl.Value, Fldr & "\")
End If
Next Cl
End Sub
Sub Write_file(CellValue As String, FolderPath As String)
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Set Fileout = fso.CreateTextFile("C:\Users\desmo\Desktop\Audit Trail.txt", True, True)
Fileout.Write CellValue & ", " & FolderPath
End Sub