[英]VBA Create a new workbook with a button click
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
Try the following code from: 请尝试以下代码:
https://msdn.microsoft.com/en-us/library/office/aa221273(v=office.11).aspx
https://msdn.microsoft.com/zh-CN/library/office/aa221273(v=office.11).aspx
Sub AddNew()
Set NewBook = Workbooks.Add
With NewBook
.Title = "All Sales" 'You can modify this value.
.Subject = "Sales" 'You can modify this value.
.SaveAs Filename:="Allsales.xls"
End With
End Sub
To get the path of the file there is already a question about that: 要获取文件的路径,已经存在以下问题:
How to get the path of current worksheet in VBA?
如何在VBA中获取当前工作表的路径?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.