i have a master.xlsx sheet where i fill in multiple columns. I would like to export the column E to a .csv file.
It's working as it should although i'd like the filename to be in the following format:
DATE-USERNAME-FIXEDTEXT-ValueFromTheCellD2(in master.xlsx).csv
So far I have I have manage this macro to create the .csv, it does contain the column E from master.xlsx, all good. The struggle however is with the filename:
Sub generatecsv()
'
' generatecsv Macro
'
'
Columns("E:E").Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.SaveAs Filename:="C:\Users\JONDOE\Documents\FixedText_" _
& Format(Now(), "DD-MMM-YYYY") & ".csv"
Windows("Miluna_1.1.xlsm").Activate
End Sub
My macro will create a filename FixedText_24-Feb-2023.csv
I can work myself on the order of the variables in the filename, but i dont understand how to get the username, since this file will be used by multiple users; and also how to get the D2 value from master.xlsx so it can be used in the final .csv filename.
To get a username i know here is the Environ("Username") function, but i dont understand the usage.
Can i put everything in the ActiveWorkbook.SaveAs Filename or do i need to create variables for the username, the D2 value, fixedtext and the date? And just refer to these variables when specifying ActiveWorkbook.SaveAs Filename?
Thank you very much for any pointers