Auto File Save

data808

Active Member
Joined
Dec 3, 2010
Messages
353
Office Version
  1. 2019
Platform
  1. Windows
So I have some VBA to save a file automatically when I click the button and here is the file path:

fname = "C:\Users\john.smith\Desktop\" & Range("G2") & "\ECIT_" _
& Format(DateValue(mnth & "-01"), "mm") & mnth & "_" & Range("G2") & ".xlsm"

The problem is that this one is specific to that one computer's desktop. How do I make it so that it doesn't matter who's desktop it is? I'm pretty sure there is a way but I can't remember. Is it something like %userprofile%?

Thanks.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Consider using Environ("UserName") instead of john.smith.
It may or may not work because the value it returns is based on the account of the logged on user.
Then there is Application.UserName, or research, such as

 
Upvote 0
Consider using Environ("UserName") instead of john.smith.
It may or may not work because the value it returns is based on the account of the logged on user.
Then there is Application.UserName, or research, such as

The Application.Username throws the profile name after the \Desktop\ which makes the path not exist. I think the Environ did something similar. Still messing around with it but no luck so far.
 
Upvote 0
Consider using Environ("UserName") instead of john.smith.
It may or may not work because the value it returns is based on the account of the logged on user.
Then there is Application.UserName, or research, such as


You have to write it like this:

fname = Environ("USERPROFILE") & Chr(92) & "Desktop\"

Then it works.
 
Upvote 0
Or
fname = Environ("USERPROFILE") & "\Desktop\"
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,263
Members
449,219
Latest member
daynle

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