Open Downloads Folder

kevinh2320

New Member
Joined
May 13, 2016
Messages
30
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.
 

Micron

Well-known Member
Joined
Jun 3, 2015
Messages
1,742
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.
 

james_lankford

Well-known Member
Joined
Jan 11, 2009
Messages
1,170
open a cmd prompt and type

cd %userprofile%

cd %userprofile%\documents

cd %userprofile%\downloads
 

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,510
In VBA like so:

Code:
Sub foo()
Debug.Print Environ("USERPROFILE") & "\Downloads"
End Sub
That is the simplest way.
More detail and other ideas:
 

kevinh2320

New Member
Joined
May 13, 2016
Messages
30
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.
 

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,510
Hi, the code snippet above and James' example is dynamic, because the userprofile parameter is associated with the current user.
 

kevinh2320

New Member
Joined
May 13, 2016
Messages
30
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.
 

Micron

Well-known Member
Joined
Jun 3, 2015
Messages
1,742
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.
 

Micron

Well-known Member
Joined
Jun 3, 2015
Messages
1,742
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.
 

james_lankford

Well-known Member
Joined
Jan 11, 2009
Messages
1,170
"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
 

Forum statistics

Threads
1,077,780
Messages
5,336,257
Members
399,073
Latest member
fairoos

Some videos you may like

This Week's Hot Topics

Top