View Single Post
 
Old 01-16-2012, 05:41 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote