1

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

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
4

1 回答 1

3

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

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

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

有关更多信息,请参阅创建新工作簿(该链接适用于 Excel 2003,因为它是我通过 Google 找到的第一个,但它仍然适用,如果您想要更新的链接,您可能可以像我一样找到它)。

于 2013-06-06T02:50:51.870 回答