+ Reply to Thread
Results 1 to 2 of 2

Search for a file in subfolders

  1. #1
    Registered User
    Join Date
    03-08-2013
    Location
    us
    MS-Off Ver
    2007
    Posts
    2

    Search for a file in subfolders

    I am trying to search all subfolders for a file to eliminate possible duplicate file names. Any help would be appreciated.

    [code]
    Sub UPDATE()
    Application.EnableCancelKey = xlInterrupt
    On Error GoTo ENDTHISSUB
    RNC = 2
    Sheets("G-DRIVE").Select
    Do While Cells(RNC, 2) <> ""
    GoSub MOVEGDRIVE
    RNC = RNC + 1
    MSGC = MsgBox("CONTINUE?", vbYesNo)
    If MSGC = vbNo Then Exit Do
    Loop
    GoTo ENDTHISSUB
    MOVEGDRIVE:
    MSGF = vbYes
    GoSub MOVEFILE
    If MSGF = vbNo Then Return
    Cells(RNC, 3).Select
    Range(ActiveCell, ActiveCell.Offset(0, 1)).Select
    Selection.Copy
    Sheets("INVAULT").Select
    RNP = Cells(1, 5)
    Cells(RNP, 2).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    RNP = RNP + 1
    Cells(1, 5) = RNP
    Sheets("G-DRIVE").Select
    Range(Cells(RNC, 1), ActiveCell.Offset(0, 24)).Select
    Selection.Delete Shift:=xlUp
    RNC = RNC - 1
    Return
    MOVEFILE:
    FCS$ = Cells(RNC, 15) & Cells(RNC, 17)
    FPS$ = Cells(RNC, 16) & Cells(RNC, 17)
    FTS$ = "C\USERS\" & Cells(1, 19) & "\DOCUMENTS\VAULT\PROJECTS\*" & Cells(RNC, 17) & "/S"
    Do While Dir(FTS$) <> ""
    MSGF = MsgBox("filename " + FPS$ + " exists.Rename?", vbYesNo)
    If MSGF = vbYes Then FPS$ = FPS$ + "_1"
    If MSGF = vbYes Then FTS$ = FTS$ + "_1"
    If MSGF = vbNo Then MSG = MsgBox("Copy failed. Try again?", vbYesNo)
    If MSGF = vbNo Then If MSG = vbNo Then MsgBox ("File Skipped")
    If MSGF = vbNo Then If MSG = vbNo Then Return
    Loop
    FileCopy FCS$, FPS$
    If Dir(FPS$) <> "" Then
    MSGD = MsgBox("COPY SUCCESS! ERASE " + FCS$ + "?", vbYesNo)
    If MSGD = vbYes Then Kill (FCS$)
    End If
    Return
    ENDTHISSUB:
    End Sub

    [code]

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Search for a file in subfolders

    Maybe this will help

    Please Login or Register  to view this content.
    When prompted, select a file in your top level folder - if there isn't one then create one as an anchor.
    Martin

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 04-21-2014, 04:03 PM
  2. how to search a file in folder and subfolders
    By rakeshredround in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-05-2012, 03:35 AM
  3. Macro to search folder including subfolders for file and open
    By kiraexiled in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-01-2012, 02:45 PM
  4. Replies: 2
    Last Post: 03-26-2012, 07:12 PM
  5. file search in subfolders
    By Pflugs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2005, 12:05 AM

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