我正在尝试在单独的实例中打开一个工作簿。目前,此工作簿已保存在桌面上。我想打开一个新的工作簿,它不会保存或位于我的系统的任何位置。以下是我当前的代码。请指教。
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
答案 0 :(得分:3)
如果要创建新的空白工作簿,请停止尝试打开现有工作簿。只需更改行
即可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找到的第一个,但它仍然适用,如果您想要更新的链接,您可能会发现它我这样做的方式。)