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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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