Open Downloads Folder

kevinh2320

Board Regular
Joined
May 13, 2016
Messages
61
I'm looking for VBA code that will open Windows File Explorer at the Downloads folder. I have the code below that will open the Documents folder and I've been able to modify it to open other locations but, can't figure out how to open the Downloads folder.

Private Sub Command1_Click()

Dim Foldername As String
Foldername = "\\server\Instructions\"

Shell "C:\WINDOWS\explorer.exe """ & "Documents" & "", vbNormalFocus

End Sub

Thanks for any help.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Posting what works isn't usually much help compared to posting what doesn't work.
Suggest you open Explorer, right click on the folder, view properties and see what the path is. Make sure your code uses that path.
 
Upvote 0
In VBA like so:

Code:
Sub foo()
Debug.Print Environ("USERPROFILE") & "\Downloads"
End Sub

That is the simplest way.
More detail and other ideas:
 
Upvote 0
I will do that going forward and thank you for the solution. Any suggestions on how to make the user part of the path dynamic. In other words, my Access database is on a network drive and many different people on the network may click on this button and run this code. I need it to open the Download file on their specific computer.
 
Upvote 0
Hi, the code snippet above and James' example is dynamic, because the userprofile parameter is associated with the current user.
 
Upvote 0
Not sure what I've got wrong here. I have this:

Private Sub Command28_Click()

Dim Foldername As String
Foldername = "\\server\Instructions\"

Shell "C:\WINDOWS\explorer.exe """ & "C:\Users\%userprofile%\Downloads" & "", vbNormalFocus

End Sub

It opens up Windows Explorer to the "Documents" folder rather than to the Downloads folder.
 
Upvote 0
If it's not a path error (Downloads folders have a way of getting relocated by users) I'd bet it's a permissions (e.g. security) issue. Go to Start>Run and type in Shell:Downloads. If the correct folder opens and you're sure your code has the correct syntax, path and spelling then I'd say its a security issue. In that case, I have not yet found a way around it. Maybe there's a way to get at whatever Windows tool is used by the Run command.
Hope that helps at least a bit.
 
Upvote 0
I managed to get this to work
VBA Code:
Dim strUser As String
strUser = Environ("username")
shell "explorer C:\Users\" & strUser & "\downloads"
During the struggle I came across threads elsewhere that show how to get the actual path from the registry in case a user relocates the folder. I also got the impression that this is easier to manage if you use a file dialog instead.
 
Upvote 0
"C:\Users\%userprofile%\Downloads" & "", vbNormalFocus

that line makes no sense at all

open a cmd prompt

do

cd \
cd %userprofile%

the first line will put you in C:\
the second line will put you in
c:\users\your_user_name

so when you do
C:\Users\%userprofile%\Downloads

what you're really doing it
C:\Users\C:\Users\your_user_name\Downloads
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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