Excel VBA to Open Folder in Explorer

gmooney

Active Member
Joined
Oct 21, 2004
Messages
252
Office Version
  1. 365
Platform
  1. Windows
Hello,

I would like to code some VBA that will open up explorer to a particular folder location and I have not been able to find any solutions.

I will add a command button to fire this code. I also want the opened explorer window to gain focus over excel.

OR another option would be to simply have the vba open up the File Open dialog box set to this same particular folder that I want to have opened.

Any suggestions?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Here is some vbScript that I borrowed from the web that will open the folder picker for you. Maybe you can use it.

Code:
Sub Main()
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Declare a variable to contain the path
'of each selected item. Even though the path is a String,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant
'Use a With...End With block to reference the FileDialog object.
    With fd
        'Use the Show method to display the File Picker dialog box and return the user's action.
        'The user pressed the action button.
        If .Show = -1 Then
            'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems
            'vrtSelectedItem is a String that contains the path of each selected item.
            'You can use any file I/O functions that you want to work with this path.
            'This example simply displays the path in a message box.
                MsgBox "The path is: " & vrtSelectedItem
            Next vrtSelectedItem
        End If
    End With
'Set the object variable to Nothing.
Set fd = Nothing
End Sub
 
Upvote 0
Thanks JLGWhiz.....that code did get the folder picker to open but I also want to have it open to a particular folder called "C:\Frozen".

Any insights to make that happen?
 
Upvote 0
This is what I do.

Create a button and add the following code to it.

Sub HyperlinkFrozenFolder()
ActiveWorkbook.FollowHyperlink Address:=Worksheets("Internal").Range("A1").Value, NewWindow:=False, AddHistory:=True
End Sub

I have a sheet named "Internal"
In range A1 have the following:

C:\Frozen\
 
Upvote 0
Actually this might suit you better.

Just add this code to your button.

Code:
Sub HyperlinkFrozen()ActiveWorkbook.FollowHyperlink Address:="C:\Frozen\", NewWindow:=False, AddHistory:=True
End Sub
 
Upvote 0
... I also want to have it open to a particular folder called "C:\Frozen"
Just add one more code line .InitialFileName = "C:\Frozen":
Rich (BB code):
    With fd
        .InitialFileName = "C:\Frozen"
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,688
Members
448,978
Latest member
rrauni

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top