Distributing a Excell file with Macro

mtagliaferri

Board Regular
Joined
Oct 27, 2004
Messages
156
I have a Excel file saved on my desktop which has a macro to import csv from another file saved on my desktop. I would like to distribute my excel file to other colleagues which will have both files saved on their desktop.
My Macro refers to my user and user name Users\123456\, therefore I would need to modify the macro for any single colleague I distribute the file to, is there a way to avoid this by changing the VBA code to read the user path?

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\123456\Desktop\UNM0007.csv", Destination:=Range("$A$1"))

Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
First calculate the connection text, then add the query:
Code:
myc = "TEXT;" & Environ("username") & "\Desktop\UNM0007.csv"
With ActiveSheet.QueryTables.Add(Connection:=myc, Destination:=Range("$A$1"))
Bye
 
Upvote 0
Sorry, I realize that I forgot some pieces, in my instruction:
Code:
myc = "TEXT;" & "C:\Users\" & Environ("username") & "\Desktop\UNM0007.csv"      'C:\Users\ was missing
 
Upvote 0

Forum statistics

Threads
1,214,848
Messages
6,121,917
Members
449,055
Latest member
KB13

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