+ Reply to Thread
Results 1 to 13 of 13

Open folder in Explorer

  1. #1
    Registered User
    Join Date
    07-03-2008
    Location
    Scotland
    Posts
    58

    Open folder in Explorer

    Good morning,

    I was wondering if it is possible to use a macro open a folder in Windows Explorer. Previously someone on this forum taught me how to open an Excel file from a macro, but in this case there will be a new file every week. As the files will all be stored in the same folder, I thought it would be easier to open the folder in the normal Explorer view and select the file manually than to change the macro every week.

    I am using Windows XP and Excel 2003. My programmes are run from the C drive, but my documents are stored on the E drive. What I am looking for really is a line that says: open in Explorer E:\data\new\processed

    Is that possible? I would be most grateful for any suggestions.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Is this what you mean?

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

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    07-03-2008
    Location
    Scotland
    Posts
    58
    Not really. I am not looking to zip a file. I wish to select a file from a specific folder. So really I am looking to skip 'Start - My Computer - E - Data - New - Processed' and go straight to the window that shows the contents of the Processed folder.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    try the code and change the title, I just posted some code that i use to select a file before zipping it.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-03-2008
    Location
    Scotland
    Posts
    58
    Have been messing with the code and have incorporated it in the overall macro, but still cannot get the pop-up window to go directly to the right folder. It opens either my desktop, or the last folder I was in when I opened a file. Been trying with ChDir, which seems to be ignored entirely, and have tried replacing bits that say 'title' with the location (I guess I didn't read your comment correctly), which isn't recognised.

    Any thoughts?

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    try this

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    hi Damien,

    Are you putting the "chdir" code before the "on error..." statement?


    Please Login or Register  to view this content.
    For more info on how this works, select the word "chdir" in the VBE & press [F1] to bring up the VBE Help files.

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  8. #8
    Registered User
    Join Date
    07-03-2008
    Location
    Scotland
    Posts
    58
    That's nailed it!

    Needed to use the ChDrive function, and had put the ChDir below instead of above the sWb = Application.GetOpenFilename(sFil, iFilterIndex, sTitle).

    Working smoothly now. Many thanks.

  9. #9
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    You just beat me to it Roy :-)
    I initially had the "chdrive" in the code too but when I looked at the Help files for "chdir" & chdrive" in the Excel 2003 VBE Help files it seemed as if the "chdrive" isn't needed if the string for the "chdir" contains a full path including the drive. Just curious, does it work without "chdrive" on your computer?

    Damien, my suggestion of putting it before the "on error" statement should work exactly the same as Roy's (I think!).

    Rob

  10. #10
    Registered User
    Join Date
    07-03-2008
    Location
    Scotland
    Posts
    58
    Hi Rob,

    well worth the experiment.

    Indeed, the ChDrive is not required because the ChDir has the drive letter in it. So it works fine without.

    As for the ChDir location, it does not work when it is below the line sWb = Application.GetOpenFilename(sFil, iFilterIndex, sTitle), but you are absolutely correct that it works when placed above the line On Error GoTo err_handler

  11. #11
    Registered User
    Join Date
    07-03-2008
    Location
    Scotland
    Posts
    58
    Please Login or Register  to view this content.
    Have come across a slight snag with the above bit of the macro. Though it opens the Open window, and I can select folders and files, but when I select a file and click 'Open', it doesn't open. Can anybody spot an obvious reason for that?
    Last edited by DamienC; 07-18-2008 at 07:43 AM.

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Damien

    Code tags please!

    You don't use the open command
    Please Login or Register  to view this content.
    Last edited by royUK; 07-18-2008 at 07:39 AM.

  13. #13
    Registered User
    Join Date
    07-03-2008
    Location
    Scotland
    Posts
    58
    Why is it that everything I get stuck on ends up with a one-line solution? I must either be thinking this is more complicated than it is, or I am just dim.

    Thanks again.

+ 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