Hello. I kindly received the macro below. I would like to change it so that it references the current directory where the starting file is located. This macro creates a bunch of new files based on the starting file and I want them all to be in the same directory as the starting file, instead of hard coding a directory in the macro. Can anyone suggest the solution to this?
The directory is currently hard coded as
Application.DisplayAlerts = False
lastrow = Range("A" & Rows.Count).End(xlUp).Row
For I = lastrow To lastrow - 158 Step -1
fname = "C:\Users\Bill\Desktop\Sony Analysis\n-1AttrSelOneR\StartingFile -" & lastrow - I + 1 & ".csv"
ActiveWorkbook.SaveAs Filename:=fname, FileFormat:=xlCSV
Application.DisplayAlerts = True