+ Reply to Thread
Results 1 to 5 of 5

VBA: Go Back A Folder and Get The Main Folder Name

  1. #1
    Registered User
    Join Date
    11-27-2012
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    65

    VBA: Go Back A Folder and Get The Main Folder Name

    Hi,

    I have a file in a subfolder, I'm trying to go back a folder and get the name of the main folder in the file (listwb - workbook) name. Its working well until going back a folder, but not after.

    My code so far is:

    Please Login or Register  to view this content.
    listwb is the workbook that I want to save with the mainfolder name in it. The mainfolder name could be 12h30 or 19h30.

    The problem is the part "sFolder.Name" is not working, the error is "Invalid Qualifier". What is that? How can I get past this error? I really need to get it done, so please any help would do alot.

    Thanks in advance!
    Sanjeev

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA: Go Back A Folder and Get The Main Folder Name

    sFolder is a simple string variable, not an object. It has no Name property.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    11-27-2012
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: VBA: Go Back A Folder and Get The Main Folder Name

    Hi shg, thanks for your reply.

    So, how can I get the name of the main folder? There is the main folder, then a subfolder and the file is in the subfolder. So, I tried to go back 2 folders and get the name of the mainfolder.

    How can it be done otherwise then? I've no idea.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA: Go Back A Folder and Get The Main Folder Name

    One way:

    Please Login or Register  to view this content.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA: Go Back A Folder and Get The Main Folder Name

    Hello sanjeevpandey,

    Here is another method. This uses the Shell application to return the folder names and paths. I think this is probably the method you wanted.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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