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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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