Save excel file multiple times with file names in another workbook.

Here is a snippet of code taken from a code I use for something similar – it should help:

Option Explicit
Sub Exportmacro()

Dim rCell As Range, rRng As Range 'define loop names
Dim NewCaseFile As Workbook 'give a name to new work book for duplicate sheet
Dim wks As Worksheet 'name of the copy of feedback
Dim sPath As String
sPath = MacScript("(path to desktop folder as string)")
'turn off screen
With Application
    '.ScreenUpdating = False  ‘only removed while testing
    '.EnableEvents = False
    '.Calculation = xlCalculationManual  ‘disabled for the moment
End With

'Student numbers in cells A7:A160 WARNING SET TO 3 STUDENTS ONLY FOR TEST
Set rRng = Worksheets("studentlist").Range("A7:A9")

    For Each rCell In rRng '<--| loop through "students" range

        'now open new workbook 
         Set NewCaseFile = Workbooks.Add

        'now save as xls with student number as filename Filename:=sPath & rCell.Value & ".xlsx"
         ActiveWorkbook.SaveAs Filename:=rCell.Value & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

        'now close duplicate file
         ActiveWorkbook.Close False

    Next rCell   '<-- next student number
End With         '<-- once all done
'turn screen back on
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

Provided to get you started – you need to edit / change it to your own needs.

Leave a Comment