Excel VBA to Open Folder in Explorer

gmooney

Board Regular
Joined
Oct 21, 2004
Messages
168
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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
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
 

gmooney

Board Regular
Joined
Oct 21, 2004
Messages
168
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?
 

ExcelPhil

New Member
Joined
Feb 21, 2010
Messages
33
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\
 

ExcelPhil

New Member
Joined
Feb 21, 2010
Messages
33
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
 

ZVI

MrExcel MVP
Joined
Apr 9, 2008
Messages
3,818
Office Version
  1. 2016
  2. 2010
  3. 2007
Platform
  1. Windows
... 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"
 

Watch MrExcel Video

Forum statistics

Threads
1,130,112
Messages
5,640,174
Members
417,130
Latest member
Darion2021

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
Top