VBA to Open Folder

mayoung

Active Member
Joined
Mar 26, 2014
Messages
257
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I am creating a custom addin how would you open just a folder

The folder path would be: C:\User\ myoung\dowloads. The myoung would be the persons computer this particular folder path is for. But several people want this addin in on there computer in excel. My question is, is there away to make a path so the VBA gets to the download folder of the persons which the addin is installed on or does each different folder path have to be set up? Or is there a work around for this?
I have the below three examples for opening a file, but how can this code be changed to open a folder?

VBA Code:
Workbooks.Open ("C:\Users\myoung\OneDrive - Bobcat Enterprises Inc\Downloads\DataminerFile.xml")

Path = "C:\Users\" & Environ("username") & "\OneDrive - Bobcat Enterprises Inc\Downloads\DataminerFile.xml"

MyPath = Environ("userProfile") & "\OneDrive - Bobcat Enterprises Inc\Downloads\Dataminer.xml"
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How about
VBA Code:
Sub mayoung()
   Dim Fname As String
   
   With Application.FileDialog(3)
      .InitialFileName = Environ("Userprofile") & "\Downloads\"
      .AllowMultiSelect = False
      If .Show Then Fname = .SelectedItems(1)
   End With
   Workbooks.Open Fname
End Sub
 
Upvote 0
How about
VBA Code:
Sub mayoung()
   Dim Fname As String
   
   With Application.FileDialog(3)
      .InitialFileName = Environ("Userprofile") & "\Downloads\"
      .AllowMultiSelect = False
      If .Show Then Fname = .SelectedItems(1)
   End With
   Workbooks.Open Fname
End Sub

Fluff Thank You.. So much to learn and never ending possibilities..
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
You're welcome & thanks for the feedback.

Would you know how to manipulate this code. Just Curious for future use if drive letter changes?

Path = "C:\Users\" & Environ("username") & "\OneDrive - Bobcat Enterprises Inc\Downloads\"
 
Upvote 0
The users folder should be on the C drive, so why would it change?
 
Upvote 0
Fluff Thank You.. So much to learn and never ending possibilities..
I tried the code and it works great except when I choose a .pdf file for example it wants to open it in excel instead of a pdf?
 
Upvote 0
That's because the code is designed to open a workbook, not a pdf.
 
Upvote 0
How about
VBA Code:
Sub mayoung()
   Dim Fname As String
   
   With Application.FileDialog(3)
      .InitialFileName = Environ("Userprofile") & "\Downloads\"
      .AllowMultiSelect = False
      If .Show Then Fname = .SelectedItems(1)
   End With
   ActiveWorkbook.FollowHyperlink Fname
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,087
Messages
6,123,050
Members
449,092
Latest member
ikke

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