Hi Marrick,
To prevent the duplicates, you could do something like:
Code:
Private Sub CmdTarget_Click()
Dim TargetFile As Variant, i As Long, StrFiles As String, StrDupes As String
'Create a FileDialog object as a File Picker dialog box.
With Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
.Filters.Clear
.Filters.Add "All Word Documents", "*.doc; *.dot; *.rtf; *.docx; *.docm; *.dotx; *.dotm", 1
.AllowMultiSelect = True
If .Show = -1 Then
' User clicked OK; show last accessed drive
Label6.Caption = "Most recent target drive: " & Left(.SelectedItems(1), InStrRev(.SelectedItems(1), "\"))
With ListBox3
If .listcount = 0 Then
.ColumnCount = 2
.ColumnWidths = "0; 60"
i = 0
Else
StrFiles = "|"
For i = 0 To .listcount - 1
StrFiles = StrFiles & .List(i, 0) & "|"
Next
i = .listcount - 1
End If
End With
' Populate the listbox
For Each TargetFile In .SelectedItems
If InStr(StrFiles, "|" & TargetFile & "|") = 0 Then
ListBox3.AddItem (TargetFile)
ListBox3.Column(1, i) = Split(TargetFile, "\")(UBound(Split(TargetFile, "\"))) 'gets the filename
i = i + 1
Else
StrDupes = StrDupes & vbCr & TargetFile
End If
Next
If StrDupes <> "" Then MsgBox "The following files were already selected: " & StrDupes, vbExclamation, "Duplicate Selection"
' Report the file count
lblTargetCount.Caption = "(" & .SelectedItems.Count & ")"
CopyButtonState
ResetButtonState
Else
' User clicked Cancel
Exit Sub
End If
End With
'Call Box2Populate
End Sub