+ Reply to Thread
Results 1 to 4 of 4

search for a file in a folder based on data, copy and paste it in another folder

Hybrid View

kboy1289 search for a file in a folder... 02-04-2013, 04:30 PM
kboy1289 Re: search for a file in a... 02-04-2013, 04:54 PM
kboy1289 Re: search for a file in a... 02-05-2013, 10:16 AM
kboy1289 Re: search for a file in a... 02-05-2013, 11:47 AM
  1. #1
    Registered User
    Join Date
    02-01-2011
    Location
    Philadelphia, Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    57

    search for a file in a folder based on data, copy and paste it in another folder

    Hi guys,

    What I am trying to do is have excel read a column of cells from a query table data source, say something like (Table_Query_from_Software_1[Column], search the value/text of each cell in that column in a specific folder in a Network Drive (I:\Folder\Subfolder) for a .zip file, copy and paste it to a folder in another drive (H:\Folder\Subfolder) all the while having a message window run through a status of each file (i.e. for each file, if it is there give it a “Found!” and then a “Successfully Moved!” message, if it can’t be found then a “Not Found!” message) I realize this last part may not be possible/ a lot to ask. thanks!
    Last edited by kboy1289; 02-05-2013 at 11:34 AM.

  2. #2
    Registered User
    Join Date
    02-01-2011
    Location
    Philadelphia, Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: search for a file in a folder based on data, copy and paste it in another folder

    **also by message i mean in one window, with a list of all the files and their respective messages, not a message window for each file. thanks again!

  3. #3
    Registered User
    Join Date
    02-01-2011
    Location
    Philadelphia, Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: search for a file in a folder based on data, copy and paste it in another folder

    here's what i have so far. something's not working. it's not reading the source path correctly (and im sure it's right) is this not possible with .zip files?

    Option Explicit
     
    Sub Copy_Files_To_New_Folder()
        Dim objFSO As FileSystemObject, objFolder As Folder, PathExists As Boolean
        Dim objFile As File, strSourceFolder As String, strDestFolder As String
        Dim x, Counter As Integer, Overwrite As String
         
        Application.ScreenUpdating = False
        Application.EnableEvents = False
         
        strSourceFolder = "I:\Funding\`JPM Bundles"
        strDestFolder = "H:\JPM Bundles"
         
        On Error Resume Next
        x = GetAttr(strDestFolder) And 0
        If Err = 0 Then
            PathExists = True
            Overwrite = MsgBox("The folder may contain duplicate files," & vbNewLine & _
            "Do you wish to overwrite existing files with same name?", vbYesNo, "Alert!")
            If Overwrite <> vbYes Then Exit Sub
    Else:
            PathExists = False
            If PathExists = False Then MkDir (strDestFolder)
        End If
    
        Set objFSO = New FileSystemObject
        Set objFolder = objFSO.GetFolder(strSourceFolder)
        Counter = 0
         
        If Not objFolder.Files.Count > 0 Then GoTo NoFiles
         
        For Each objFile In objFolder.Files
            
             If InStr(1, objFile.Name, ".zip") Then
          
            objFile.Copy strDestFolder & "\" & objFile.Name
             
            Counter = Counter + 1
             
             End If
             
        Next objFile
         
        MsgBox "All " & Counter & " Files from " & vbCrLf & vbCrLf & strSourceFolder & vbNewLine & vbNewLine & _
        " copied/moved to: " & vbCrLf & vbCrLf & strDestFolder, , "Completed Transfer/Copy!"
         
        Set objFile = Nothing: Set objFSO = Nothing: Set objFolder = Nothing
         
        Exit Sub
         
    NoFiles:
        MsgBox "There Are no files or documents in : " & vbNewLine & vbNewLine & _
        strSourceFolder & vbNewLine & vbNewLine & "Please verify the path!", , "Alert: No Files Found!"
        Set objFile = Nothing: Set objFSO = Nothing: Set objFolder = Nothing
         
        Application.ScreenUpdating = True
        Application.EnableEvents = True
         
        Exit Sub
         
    
    End Sub
    Last edited by kboy1289; 02-05-2013 at 11:36 AM.

  4. #4
    Registered User
    Join Date
    02-01-2011
    Location
    Philadelphia, Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: search for a file in a folder based on data, copy and paste it in another folder

    bump, anyone have any ideas? it looks like its not recognizing the files within the folder, eventhough the source folder path is correct. also is there a way to tweak it so that it can read every row in a specific column of a data query table and search for each file? such as Table_Query_from_Software_1[Column]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1