Results 1 to 20 of 37

Thread: Copy/Paste files into new folders based on condition

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #28
    Ken I have attached images of what's happening. Hopefully this helps? The Candidate Range File appears inside the folder, the code is looping correctly (ie. keeps going 'til 5 files are copied even though I changed the filepaths so that Topic2 appears twice), however the topic files appear outside the candidate folder??? I don't know why?

    The code for this is below. (It's using late binding fso)

      Dim fso As Object, pf As Object  'Late Binding
     With fso
        If Not .FolderExists(p2 & "Files") Then _
          .GetFolder(p2).SubFolders.Add "Files"
        p2 = p2 & "Files\"
        Set pf = .GetFolder(p2)
        For Each c2 In rng2
          If Not .FolderExists(p2 & c2) Then pf.SubFolders.Add c2
        Next c2
      
        'Iterate each candidate reference to update Main sheet.
        For i = 1 To rng2.Rows.count
          wsM.[F1] = rng2(i).Offset(, -1)
          rn = Trim(wsM.[F1])
          count = 1
          'Iterate each file item and copy files and make pdf for candidate.
          For Each c1 In rng1
            If c1.Offset(, 3) <= 0.5 And count <= 5 And _
            Not .FileExists(p2 & rn & "." & .GetFileName(c1)) Then
              If .FileExists(c1) Then
              .CopyFile c1, p2 & "\" & rn & "." & .GetFileName(c1)
                count = count + 1
              End If
            End If
          Next c1
          wsM.Range("A1:H29").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            p2 & Trim(wsM.[c2]) & "\" & Trim(wsM.[c2]) & ".pdf", Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
        Next i
        
      End With
    '--------------------------------------
    Attached Images Attached Images

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •