I am trying to open a workbook in separate instance. Currently, this workbook is saved on the desktop. I would want to open a new workbook which is not saved or located anywhere on my system. Below is the current code which I have. Please advise.
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
If you want to create a new blank workbook, stop trying to open an existing one. Just change the line
Set wbExcel = xlApp.Workbooks.Open("C:\Users\PRASHPRA\Desktop\Book.xls")
'Add a new, empty workbook Set wbExcel = xlApp.Workbooks.Add
For more information, see Creating a New Workbook (the link is for Excel 2003, because it’s the first one I found via Google, but it still applies, and if you want a more recent link you can probably find it the same way I did).