+ Reply to Thread
Results 1 to 13 of 13

Open folder in Explorer

Hybrid View

  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?

    Option Explicit
    
    Sub openfile()
        Dim sFil   As String
        Dim sTitle As String
        Dim sWb    As String
        Dim iFilterIndex As Integer
    On Error GoTo err_handler
        ' Set up list of file filters
        sFil = "Excel Files (*.xls),*.xls"
        ' Display *.xls by default
        iFilterIndex = 1
        ' Set the dialog box caption
        sTitle = "Select  File to Zip"
        ' Get the filename
        sWb = Application.GetOpenFilename(sFil, iFilterIndex, sTitle)
    
        Workbooks.Open Filename:=sWb
    Exit Sub
    err_handler:
    MsgBox "No selection made"
    End Sub
    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.

    Option Explicit
    Sub openfile()
        Dim sFil   As String
        Dim sTitle As String
        Dim sWb    As String
        Dim iFilterIndex As Integer
    On Error GoTo err_handler
        ' Set up list of file filters
        sFil = "Excel Files (*.xls),*.xls"
        ' Display *.xls by default
        iFilterIndex = 1
        ' Set the dialog box caption
        sTitle = "Select  File to open"
        ' Get the filename
        sWb = Application.GetOpenFilename(sFil, iFilterIndex, sTitle)
    
        Workbooks.Open Filename:=sWb
    Exit Sub
    err_handler:
    MsgBox "No selection made"
    End Sub

  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

    Option Explicit
    
    Sub openfile()
        Dim sFil   As String
        Dim sTitle As String
        Dim sWb    As String
        Dim iFilterIndex As Integer
        On Error GoTo err_handler
        ' Set up list of file filters
        sFil = "Excel Files (*.xls),*.xls"
        ' Display *.xls by default
        iFilterIndex = 1
        ' Set the dialog box caption
        sTitle = "Select  File to open"
        ChDrive "C:"
        ChDir "C:\My Documents"
        ' Get the filename
        sWb = Application.GetOpenFilename(sFil, iFilterIndex, sTitle)
        MsgBox sWb
        ' Workbooks.Open Filename:=sWb
        Exit Sub
    err_handler:
        MsgBox "No selection made"
    End Sub

  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?


    '... leave the above the same
    ChDir "D:\TMP"
    On Error GoTo err_handler
    '... leave the rest the same
    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...

+ 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