Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Create a new workbook with a button click

Tags:

People also ask

How do I create a new workbook in VBA?

To create a new workbook using VBA, you need to use the “Workbooks. Add” method. When you use this method, it inserts a new workbook (without saving it) and activates it after that. It works like when you press the keyboard shortcut CONTROL + N.


I'm trying to create a macro that creates a new workbook when pressing a button on the already existing workbook. I would like to save the newly created workbook in the same folder as the exiting workbook and give it a new name? Could somebody help me please?

Thank you very much in advance!

That's the code I have until now but it doesn't work as I want it (object not found and doesn't save it in the same folder):

Sub CreateNewWorkBook()

'Adding New Workbook
Workbooks.Add
'Saving the Workbook
 ActiveWorkbook.SaveAs Filename:=thisWb.Path & "\Test.xls"
 ActiveWorkbook.Close savechanges:=False

End Sub

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!