Link to home
Start Free TrialLog in
Avatar of onyourmark
onyourmark

asked on

reference current directory

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
"C:\Users\Bill\Desktop\Analysis\n-1AttrSelOneR\
Thank you.
Sub decrementrows()
    Application.DisplayAlerts = False
    lastrow = Range("A" & Rows.Count).End(xlUp).Row
    For I = lastrow To lastrow - 158 Step -1
        Cells(I, 1).EntireRow.Delete
        fname = "C:\Users\Bill\Desktop\Sony Analysis\n-1AttrSelOneR\StartingFile -" & lastrow - I + 1 & ".csv"
        ActiveWorkbook.SaveAs Filename:=fname, FileFormat:=xlCSV
    Next I
    Application.DisplayAlerts = True
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of TinTombStone
TinTombStone

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of onyourmark
onyourmark

ASKER

Great thanks.