Saving with vba with current user spefic directory

Mattm3486

New Member
Joined
Nov 4, 2016
Messages
2
Hello,
Still new to excel and needing a little help. I have a workbook that i need to have the user save weekly into their archive folder located within the same folder the workbook is held, however the file path changes depending on the user. I know i had it close as i can get it to save into the save folder as the workbook but not into the archive folder located in the same directory.
Workbook is in :
G:\_OVERDRAFT\AMF Project Files\Tracker\**Current user**
and inside this directory is the folder archive.

what i have without it needing to change users is below (user is Matt)

ActiveWorkbook.SaveAs Filename:= _
"G:\_OVERDRAFT\AMF Project Files\Tracker\Matt\Archive\Function Sheet - " & Format(Date, "dd-mm-yyyy") & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

Any help would be appreciated , thank you
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi @★ Mattm3486,

Try this

Code:
Sub test()
  Dim path1 As String, UserName As String, path2 As String, sFile As String
  path1 = "G:\_OVERDRAFT\AMF Project Files\Tracker\"
  UserName = Environ("username")
  sFile = "Function Sheet - " & Format(Date, "dd-mm-yyyy") & ".xlsm"
  path2 = path1 & UserName & "\Archive\" & sFile
  ActiveWorkbook.SaveAs path2, FileFormat:=xlOpenXMLWorkbookMacroEnabled
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

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