gpt4 book ai didi

excel - 创建一个未保存的空白工作簿

转载 作者:行者123 更新时间:2023-12-04 22:07:46 25 4
gpt4 key购买 nike

我正在尝试在单独的实例中打开工作簿。目前,此工作簿保存在桌面上。我想打开一个新的工作簿,它没有保存或位于我系统的任何位置。以下是我拥有的当前代码。请指教。

Sub New_Excel()
'Create a Microsoft Excel instance via code
'using late binding. (No references required)
Dim xlApp As Object
Dim wbExcel As Object

'Create a new instance of Excel
Set xlApp = CreateObject("Excel.Application")

'Open workbook, or you may place here the
'complete name and path of the file you want
'to open upon the creation of the new instance
Set wbExcel = xlApp.Workbooks.Open("C:\Users\PRASHPRA\Desktop\Book.xls")

'Set the instance of Excel visible. (It's been hiding until now)
xlApp.Visible = True

'Release the workbook and application objects to free up memory
Set wbExcel = Nothing
Set xlApp = Nothing
End Sub

最佳答案

如果要创建新的空白工作簿,请停止尝试打开现有工作簿。换行就好

Set wbExcel = xlApp.Workbooks.Open("C:\Users\PRASHPRA\Desktop\Book.xls") 


'Add a new, empty workbook
Set wbExcel = xlApp.Workbooks.Add

如需更多信息,请参阅 Creating a New Workbook (该链接适用于 Excel 2003,因为它是我通过 Google 找到的第一个,但它仍然适用,如果您想要更新的链接,您可能可以像我一样找到它)。

关于excel - 创建一个未保存的空白工作簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16952914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com