Creating a workbook and saving it with a given name

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have code that adds a name to a list and I am trying to write code to create a workbook and call it by the name that was added to the list.

This is what I have so far but this code just highlights the word Filename and says named argument not found.

What is wrong with my code?

VBA Code:
Sub AddYP()
Dim NewYP As String
    NewYP = Tracker.Cells(5, 4)
    YP.Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = NewYP
    Call CreateWB(NewYP)
End Sub
Sub CreateWB(NewYP As String)
Dim wb1 As Workbook
    Workbooks.Add Filename:=NewYP
    'wb1.Name = NewYP & ".xlsm"
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try using
VBA Code:
ActiveWorkbook.SaveAs Filename:=NewYP
OR
VBA Code:
Workbooks.Add.SaveAs Filename:=NewYP
 
Upvote 0
Thanks Michael. How do I make it a macro enabled workbook
VBA Code:
    Workbooks.Add.SaveAs Filename:=ThisWorkbook.Path & "\Young People\" & NewYP
 
Upvote 0
I worked it out
VBA Code:
    Workbooks.Add.SaveAs Filename:=ThisWorkbook.Path & "\Young People\" & NewYP, FileFormat:=52
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

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