+ Reply to Thread
Results 1 to 8 of 8

Browse for folder error

  1. #1
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Browse for folder error

    Good morning, afternoon or evening (depending on wherer you are),

    How do I get the function below to get the folder name below to pass to the sub?
    Please Login or Register  to view this content.
    Right now it gives me nothing. I keep getting Run-time error '13': Type mismatch. When I remove the loop and put FolderName in the MsgBox it gives me the correct folder that I chose, so the function works, but I can't get it to work with the loop. Can anyone help me out?

    Thanks.

    abousetta
    Last edited by abousetta; 04-29-2010 at 08:21 PM.

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

    Re: Browse for folder error

    Maybe like this:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Browse for folder error

    Thanks shg. I tried the code you posted but for some reason regardless of the folder I chose, it gave me only the txt files on C:\. I don't know why its ignoring my decision and defaulting to C:\.

    I have been working on it all day and make a breakthrough (at least a small one) and got the original code to work. Here is the modified code:

    Please Login or Register  to view this content.

    Even though, it works only to give me the file names in a msg box. When I try to combine it with other code, I get an error saying that the file does not exist. Below is an example which incorporates the code above with the code that you generously created for me in a previous thread.


    Please Login or Register  to view this content.
    I don't know why it doesn't work even though I got to work earlier today, but like an idiot I forgot to save the file and I can't get it to work again. I have been pulling my hair out at the roots because I am so frustrated with this. I hope you can help me resolve this issue.

    Thanks again.

    abousetta

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Browse for folder error

    Hi shg,

    I dont' know if there is something wrong with my system or what, but last night I finally got it work. So to test it, I saved the xlsm file and reopened it to see if worked and it wouldn't work again. It started giving me the same errors again. As a last ditch attempt I am uploading the excel file with the two modules containing the modified code that at one time worked and the code you posted yesterday. Also I am uploading three identical dummy text files that I used for test runs.

    I hope you can help me out because this looping through files issues is critical to my project.

    Thanks.

    abousetta
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Browse for folder error

    Hi again,

    OK, now I know that I am not crazy because I got it to work again (this time on another computer). Once I saved the file and reopened it, it won't work again. I have stripped the code down the to the basic part to show where it hangs.

    Please Login or Register  to view this content.

    It stops at the following line of code:
    Please Login or Register  to view this content.
    When I change the code to just send the file name to a messag box, it works fine, but it seems to have a problem opening the file. I hope you could tell me why this happening.

    Thanks.

    abousetta

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Browse for folder error

    Another addition to this saga.

    I have checked again on a completely different computer than the ones I have used before and the problem doesn't seem to be with the BrowseForFolder Function. I am assuming this because I have replaced the function with the actual path and it worked... the first time. And then every time after that it gave the Run-time error '53': File not found. Even when I create a new workbook and add the code to a new module, it still gives me the same error. Its as if the files are now locked for use by only the first instance of the macro running. Could there be some hidden link that is causing this bug?

    abousetta

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Browse for folder error

    This is the technique I use most often to select a folder name:
    Please Login or Register  to view this content.

    You could add in an abort if the user failed to select a folder:
    Please Login or Register  to view this content.

    With these, you wouldn't need to call a separate standalone function.
    Last edited by JBeaucaire; 04-29-2010 at 05:07 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Question Re: Browse for folder error

    Thanks JB... It has been a very big help. I tried it out right now and maybe the real culprit was the function after all. I don't know anymore...

    I want to be optimistic and say that it is working fine but I don't want to jinx myself. I will say that my first trial run worked well and I will keep testing it in different environments and make sure the issue truely is solved.

    Thanks again everyone. And of course a special thanks to shg and JB who have put up with my numerous posts.

    Best wishes,

    abousetta

+ 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