+ Reply to Thread
Results 1 to 2 of 2

Searching for files in various folders help

  1. #1
    Registered User
    Join Date
    02-12-2018
    Location
    Texas, US
    MS-Off Ver
    2010
    Posts
    14

    Searching for files in various folders help

    Hello!

    First, thank you for reading. I've used VBA tons of times in the past to make my life easier, but now I'm actually studying Programming to get a degree in it so I know what it is that I'm doing instead of recording macros or modifying code. The issue is that at this point in my studies, I familiar with Python, so I am having trouble with the VBA language.

    I was trying to create a Macro in which the user would input a string, then the macro would search 3 separate folders (A, B & C) and their subfolders for file names that would contain the string (be partial file name). The macro would then open said files.

    All my attempts have failed. I've looked around the past few days, but haven't had any luck.

    Here is the VBA code for the first folder (Folder A) that I've most recently tried (and failed). And because I'm been programmed to do so (ha, ha) I put the psuedocode I wrote for my macro underneath. Please forgive any rookie mistakes.

    Thank you for any help.


    [code] Sub allFolders()

    Dim tlcNumber As String
    Dim folderA As String
    Dim fileA As String

    tlcNumber = InputBox("Enter TLC in either X-XX, XX-XX or XX-XXX format()")
    folderA = "\\file path"
    fileA = Dir(folderA & "\*.xlsm")
    Do Until fileA = ""
    Workbook.Open Filename:=tlcNumber & "" & fileA
    fileA = Dir
    Loop

    End Sub [code]





    All Folders Psuedocode
    //Declare variables
    Declare String tlcNumber

    //global constants as the location will never change
    Set folderA = network location
    Set folderB = network location
    Set folderC = network location

    // Call Modules
    Call Main()
    Call findTLC(tlcNumber)
    Call openFiles(tlcNumber)


    Module findTLC (String tlcNumber)
    //To input the TLC for the line you are looking for
    Display “Enter the TLC to identify the line in XX-XX, X-XXX or XX-XXX format.”
    Input tlcNumber

    Module openFiles(tlcNumber)
    // Search the TLC number in the A folder and subfolders then open file
    Find(tlcNumber folderA)
    For files in folderA
    If tlcNumber name in file Then
    Open(file)
    Else
    Display “No file found”

    // Search the TLC number in the B folder and subfolders then open file
    Find(tlcNumber, folderB)
    For files in folderB
    If tlcNumber name in file Then
    Open(file)
    Else
    Display “No file found”

    // Search the TLC number in the C folder and subfolders then open file
    Find(tlcNumber, folderC)
    For files in folderC
    If tlcNumber name in file Then
    Open(file)
    Else
    Display “No file found”
    Call Main():
    Last edited by epactheactor; 10-11-2018 at 11:20 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: Searching for files in various folders help

    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 6)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ 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. Create folders and save text files to these folders
    By bloomingcarrot in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-03-2014, 08:14 PM
  2. Use Excel VBA to Copy multiple files from different source folders to different folders
    By mm1234mail in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2014, 01:17 PM
  3. How to copy and rename files in vba by searching multiple folders for files
    By razorace in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2014, 04:21 AM
  4. Searching folders for list of files
    By joltremari in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-03-2014, 02:09 PM
  5. Replies: 1
    Last Post: 09-12-2013, 09:23 PM
  6. VBA code for searching file through folders and sub folders
    By vikas189 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-05-2012, 06:00 PM
  7. Create folders and move and copy files into that folders
    By vijaybharthi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-31-2010, 04:01 AM

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