+ Reply to Thread
Results 1 to 9 of 9

Macro to open Folder and File

  1. #1
    Forum Contributor
    Join Date
    06-25-2012
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2010
    Posts
    201

    Macro to open Folder and File

    Hi. I need a vba code to open a subfolder thats is created where the .xlsm file is being executed. I have a file called Menu.xlsm inside a folder called RESTAURANT(in desktop). Inside this folder i have Menu file (which i'm running) and a subfolder called EXTRACT. I want a peace of code that runs on Menu file to open EXTRACT. The thing is that Menu file may not allways be inside RESTAURANT folder or this folder may not allways be located in desktop. The constant is the subfolder EXTRACT which is allways inside a folder located somewhere with Menu.xlsm in the same folder as EXTRACT. Basicaly i need it to open EXTRACT independent where it is located. If ecel cannot find it inside the folder where Menu.xlsm is i´ll handle it Herror Handler.

    The same way i need a code to open a print.xlsm file that is located in the same folder as Menu.xlsm file. This one is another macro to be assigned to other button. But i guess it uses the same parameters as the first one.

    Hope someone could help with this

    Thank you

  2. #2
    Forum Contributor
    Join Date
    10-19-2012
    Location
    Omaha, Nebraska USA
    MS-Off Ver
    Excel 2010
    Posts
    249

    Re: Macro to open Folder and File

    Hi Taislin,

    Here is the code to set the default folder to "EXTRACT" when it is always in the same folder as the Menu.xlsm file.

    Please Login or Register  to view this content.
    Hope that helps,

    Daniel

  3. #3
    Forum Contributor
    Join Date
    06-25-2012
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Macro to open Folder and File

    @djbomaha

    Thank you it was great. Only one more question. How about to open directly the file print.xlsm that is located in the same folder as Menu.xlsm. Use the same code and substitute ExTRACT by Print.xlsm? Thank you

  4. #4
    Forum Contributor
    Join Date
    10-19-2012
    Location
    Omaha, Nebraska USA
    MS-Off Ver
    Excel 2010
    Posts
    249

    Re: Macro to open Folder and File

    Hi,

    I'm glad it worked. To open the "Print.xlsm" file automatically, the code would be:

    Please Login or Register  to view this content.
    Thanks, Daniel

  5. #5
    Forum Contributor
    Join Date
    06-25-2012
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Macro to open Folder and File

    Thank you very much. Solved. Perfect.

  6. #6
    Forum Contributor
    Join Date
    06-25-2012
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Macro to open Folder and File

    Quote Originally Posted by djbomaha View Post
    Hi Taislin,

    Here is the code to set the default folder to "EXTRACT" when it is always in the same folder as the Menu.xlsm file.

    Daniel
    Sorry disturbing you again. The macro you provided works perfectly but have one issue though... when folder opens and i select to open a file inside or simply cancel it gives error. I would like it just to go back to the workbook without doing nothing even if i press open or cancel. Need to say that i add error handler to alert the user when he opens the folder and it is not created. So on error the macro says that the folder was not created and for the user create it. But when folder is now created and i press cancel or ok my message is showned because of this error. Can you help me?

  7. #7
    Forum Contributor
    Join Date
    06-25-2012
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Macro to open Folder and File

    By the way when i try the second macro to open the file it opens but at the end it gives the same error as the first.

  8. #8
    Forum Contributor
    Join Date
    10-19-2012
    Location
    Omaha, Nebraska USA
    MS-Off Ver
    Excel 2010
    Posts
    249

    Re: Macro to open Folder and File

    Hi Taislin,

    The first macro giving an error if no selection is made makes sense. I'm not sure why the code to open the Print.xlsm file would give an error since once it is open, it is successfully completed. If everything works as it should and you want to get rid of the annoyance of the errors, I would put the magical "On Error Resume Next" line in the code so it won't display the error. If there is no file selected, then the code won't run, so the error on the first one is not really an error, it is a choice by the user not to run the program when they hit "cancel".

    Thanks, Daniel

  9. #9
    Forum Contributor
    Join Date
    06-25-2012
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Macro to open Folder and File

    Thank you for your response. The error that the second one gives also didnt understand. Dont know if it is because i have error handler alerting (in case that the file dont exist) to the user put it in the folder or check the name. On error resume next surely solve the problem but could i use it with error handler? Because i would like to alert the user when the folder is not created or in the second macro when the file is not there or misspeling the name.

    Thank you.

    By the way my name is Mário.

    Regards from Portugal

+ 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