How to have a dynamic file path for a desktop folder in power query macro?

Indominus

Board Regular
Joined
Jul 11, 2020
Messages
160
Office Version
  1. 2016
Platform
  1. Windows
Hi. I am building a macro power query and I want to share it with other people. It uses a folder saved on your desktop but obviously people have different logins. How can I change the source name to recognize the username for the desktop? Thank you. Here is the beginning of my code

VBA Code:
ActiveWorkbook.Queries.Add Name:="Manifests", Formula:= _

 "let" & Chr(13) & "" & Chr(10) & " Source = Folder.Files(""C:\Users\username\Desktop\Manifests"")," & Chr(13) & "" & Chr(10) & " #""Filtered Hidden Files1"" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true)," & Chr(13) & "" & Chr(10) & " #""Invoke Custom Function1"" = Table.AddColumn(#""Filtered Hidden Files1"", ""Transform File from Manifests"", each #""Transform File from Manifests""([Content]))," & Chr(13) & "" & Chr(10) & " #""Renamed Columns1"" =" [B]& _[/B]
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
If I understood your needs correctly.
This is from cellphone, so it's not tested.

VBA Code:
Environ("USERPROFILE") & "\Desktop"

should return current user profile folder...
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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