+ Reply to Thread
Results 1 to 10 of 10

VBA Code to find a Folder name within a Parent folder that contains defined text

  1. #1
    Registered User
    Join Date
    07-22-2014
    Location
    uk
    MS-Off Ver
    vb 6.5
    Posts
    6

    VBA Code to find a Folder name within a Parent folder that contains defined text

    Hello,
    I've searched the forum and found numerous variations of my problem but none solve my problem exactly.
    And with the numerous variation of answers, I haven't a clue where to begin.
    Basically, I have an Excel VBA Macro for creating/logging drawing numbers.
    Each drawing belongs to a job number.
    Each job number has a folder name containing the job number followed by a description (ie 999999 - bracket assembly) for storing drawing pdf's.
    The job number is only known as a 6 figure number in the drawing creation process BUT for the PDF saving process it is a string value...as my example above

    I have to change my process by pre-creating the Job Number folder, then have the macro look for the appropriate folder by searching the parent folder for a sub folder containing the job number (always the first 6 figures).

    There are a number of threads that touch on my problem but none actually solve it. It's best i start this thread from scratch cos I haven't a clue how to put a starting code in this thread...there are that many different ways...and I have no clue which method is the best.

    I want to insert in my macro some code that searches...

    The parent folder for a folder containing the job number.
    The macro value for the parent folder is P:\engineering\drawings\ (this never changes).
    the macro value for the job number is iOpenair (it's an entry that is entered as start the macro).
    Imagine the value for the job number is "999999"...so the search would be for "999999*.*"
    The code needs to search the parent folder, find the folder name that begins with a six digit number. Capture the complete name of the folder and store that name as a Dim value that I can call up elsewhere in my macro.

    any and all help is much appreciated cos I've given up.

    regards

    gary

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: VBA Code to find a Folder name within a Parent folder that contains defined text

    hi Gary, welcome to Excelforum, try sort of this:

    Please Login or Register  to view this content.
    Last edited by watersev; 07-23-2014 at 10:46 AM.

  3. #3
    Registered User
    Join Date
    07-22-2014
    Location
    uk
    MS-Off Ver
    vb 6.5
    Posts
    6

    Re: VBA Code to find a Folder name within a Parent folder that contains defined text

    Cheers for the welcome...
    I think I've scoured this website for a complete day...putting things together and trying things out with no success...
    my brain's full of tried, tested and failed ways of doing things now!
    anyways...thanks for my starter for 10...
    unfortunately it errors at fso with variable undefined...
    i've tried changing it...but not knowing what it's doing, I'm failing.

    cheers

    Gary

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: VBA Code to find a Folder name within a Parent folder that contains defined text

    it was me not adding variables dimension line
    Last edited by watersev; 07-23-2014 at 12:37 PM.

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: VBA Code to find a Folder name within a Parent folder that contains defined text

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-22-2014
    Location
    uk
    MS-Off Ver
    vb 6.5
    Posts
    6

    Re: VBA Code to find a Folder name within a Parent folder that contains defined text

    Cheers...I'll try it in the morning.
    Regards
    Gary

  7. #7
    Registered User
    Join Date
    07-22-2014
    Location
    uk
    MS-Off Ver
    vb 6.5
    Posts
    6

    Re: VBA Code to find a Folder name within a Parent folder that contains defined text

    absolutely perfect...
    I can use the parts
    its unbelievable really...an internet search over 2 days...coming up with around several different variations...using different command methods.. of trying to do this example...I decide to register with the website...create a post and get a solution in 1 1/2 hours!

    this works perfectly and i hope someone else wanting to do the same stumbles on this post.
    and just FYI...nothing to do with the solution, but here's how I added your code into mine...

    Sub checkFolders(iOpenAir As Long)
    Dim oFS
    Dim sIssuedPath
    ' Dim sDraftPath
    ' Dim sObsPath
    Dim sOpenAir As String
    Dim FoundFolderName As String, fso As Object, user_input, subf

    sOpenAir = iOA_to_String(iOpenAir)

    'sIssuedPath = RELEASED_DRAWINGS_FOLDER & "Issued\" & sOpenAir
    'sDraftPath = RELEASED_DRAWINGS_FOLDER & "Draft\" & sOpenAir
    'sObsPath = RELEASED_DRAWINGS_FOLDER & "Obsolete\" & sOpenAir

    Set fso = CreateObject("scripting.filesystemobject")

    user_input = iOpenAir
    If user_input = "False" Then Exit Sub

    For Each subf In fso.getfolder("P:\DBS Engineering\Drawing Control\Issued\").subfolders
    If InStr(subf.Name, user_input) = 1 Then
    FoundFolderName = subf.Name
    Exit For
    End If
    Next

    If FoundFolderName <> "" Then sIssuedPath = FoundFolderName

    thankyou...
    : )

    Regards

    Gary
    Last edited by knowga; 07-24-2014 at 03:54 AM.

  8. #8
    Registered User
    Join Date
    07-22-2014
    Location
    uk
    MS-Off Ver
    vb 6.5
    Posts
    6

    Re: VBA Code to find a Folder name within a Parent folder that contains defined text

    Is there a setting to say that this thread is solved?

  9. #9
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: VBA Code to find a Folder name within a Parent folder that contains defined text

    hi there, as per Forum Rules:

    If your problem is solved, please say so clearly, and mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Dropdown option or Edit button will not appear -- ask a moderator to mark it.

  10. #10
    Registered User
    Join Date
    07-22-2014
    Location
    uk
    MS-Off Ver
    vb 6.5
    Posts
    6

    Re: VBA Code to find a Folder name within a Parent folder that contains defined text

    Solved...and marked as Solved.

+ 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. [SOLVED] VBA Code open files in folder, copy text to workbook-Next time folder opened copy only new
    By Bikeman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-02-2013, 07:59 PM
  2. Parent Folder
    By kingdt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-22-2008, 05:08 AM
  3. Replies: 6
    Last Post: 02-21-2006, 04:25 AM
  4. [SOLVED] get the parent folder of the working folder
    By tom taol in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-15-2005, 12:05 PM
  5. Parent Folder
    By Bruce in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-05-2005, 11:05 PM

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