I am trying to use VBA code below to create multiple files by using template and given range list of names (create individual files by names list).
I am getting below error message.
Public Sub SaveTemplate()
Const strSavePath As String = "C:\Users\Madhukar.Galpalli\OneDrive - Avantor\Desktop\My Folder\Macro\Macro Test\"
Const strTemplatePath As String = "C:\Users\Madhukar.Galpalli\OneDrive - Avantor\Desktop\My Folder\Macro\Macro Test\template.xlsx"
Dim rngNames As Excel.Range
Dim rng As Excel.Range
Dim wkbTemplate As Excel.Workbook
Set rngNames = ThisWorkbook.Worksheets("Sheet1").Range("A1:A200").Cells
Set wkbTemplate = Application.Workbooks.Open(strTemplatePath)
For Each rng In rngNames.Cells
wkbTemplate.SaveAs strSavePath & rng.Value
Next rng
wkbTemplate.Close SaveChanges:=False
End Sub
What is the error message mean, I see the file is saved at correct path and the template name is "template.xlsx"
Thank you
Madhukar
I am getting below error message.
Public Sub SaveTemplate()
Const strSavePath As String = "C:\Users\Madhukar.Galpalli\OneDrive - Avantor\Desktop\My Folder\Macro\Macro Test\"
Const strTemplatePath As String = "C:\Users\Madhukar.Galpalli\OneDrive - Avantor\Desktop\My Folder\Macro\Macro Test\template.xlsx"
Dim rngNames As Excel.Range
Dim rng As Excel.Range
Dim wkbTemplate As Excel.Workbook
Set rngNames = ThisWorkbook.Worksheets("Sheet1").Range("A1:A200").Cells
Set wkbTemplate = Application.Workbooks.Open(strTemplatePath)
For Each rng In rngNames.Cells
wkbTemplate.SaveAs strSavePath & rng.Value
Next rng
wkbTemplate.Close SaveChanges:=False
End Sub
What is the error message mean, I see the file is saved at correct path and the template name is "template.xlsx"
Thank you
Madhukar