1

I am trying to open a windows folder (Downloads folder) via a commandbutton in a userform in Excel. However I want to use a generic folder path to access the downloads folder so whoever has this excel file can open their downloads folder. I got this code from the internet but it doesn't work, it only opens the document folder which I believe is the default folder.

Private Sub CommandButton1_Click()
   Shell "explorer.exe" & " " & "C:\Users\%USERNAME%\Downloads", vbNormalFocus
End Sub

How can I achieve that?

SuleymanSah
  • 17,153
  • 5
  • 33
  • 54

1 Answers1

3

You want to use the Environ() function:

"C:\Users\" & Environ("Username") & "\Downloads"

Environ Function

braX
  • 11,506
  • 5
  • 20
  • 33
  • 1
    THANK YOUUU!!! It worked, you made my day. Have a nice weekend. –  Dec 01 '19 at 08:01
  • This is the code I used to make it worked. Private Sub CommandButton1_Click() Shell "explorer.exe" & " " & "C:\Users\" & Environ("Username") & "\Downloads", vbNormalFocus End Sub –  Dec 01 '19 at 08:05