Create Multiple files using template with file names from the range list

MadhukarG

New Member
Joined
Apr 28, 2022
Messages
18
Platform
  1. Windows
  2. Web
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

1651163042473.png


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
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You are attempting to SAVE and NAME workbooks that don't exist. You must first create the workbook ... then name an save.

VBA Create New Workbook (Excel File)
Thank you for reply, However not getting as what workbook is not created, I have already saved the workbook named as "template.xlsx" on the given path, and in that template file in cell A1 to A2 two names are updated. I want to create two files with names given in the template saved.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,603
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top