Include Username / userprofile in filename when saving using vba

monmon

Board Regular
Joined
Apr 1, 2013
Messages
84
Hi, I would like to find out how can I include the username of the person who has logged into the PC in the filename using VBA?

I heard of Environ[username/userprofile] and tried it but can't seem to make it work.

Please note that the macro is a shared document so that anyone that have access to the drive can use it.

Thanks in advance!

Code:
Workbooks.Add
   
    ActiveWorkbook.SaveAs Filename:= _
        "S:\Shared\Hello\Yes_High_" & Format(Date, "yyyymmdd") & ".xls" _
        , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
It would be something like:
Rich (BB code):
ActiveWorkbook.SaveAs Filename:= _
        "S:\Shared\Hello\Yes_High_" & environ("Username") & Format(Date, "yyyymmdd") & ".xls" _
        , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
 
Upvote 0

Forum statistics

Threads
1,216,182
Messages
6,129,364
Members
449,506
Latest member
nomvula

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