# Simultaneously opening a spreadsheet in Excel and Analytica

It can be useful to have the same spreadsheet open in Excel at the same time you are reading from it or writing to it from Analytica using the Spreadsheet functions. But when you attempt to open it simultaneously, what happens is confusing and seems at first inconsistent. This page demystifies what is going on and discusses how to get them open at the same time.

## Open in Excel first

The easiest and least confusing way to view a spreadsheet in Excel at the same time that your model is reading from or writing to it is to open the model in Excel before you evaluate SpreadsheetOpen from your model. When the model is already open in an Excel instance, SpreadsheetOpen connects to the already-open instance, and the data you see in Excel will be exactly the data that you model reads, and any data written by your model will be immediately visible in the Excel UI. This is especially nice when debugging.

## SpreadsheetOpen first, but with Excel running

The key concept to understand for this case is the fact that there is only ONE Excel.exe process running. You can verify this by looking in Task Manager. Using Unhide only works when the Excel UI and the Excel instance used by SpreadsheetOpen are the same process instance.

## SpreadsheetOpen before Excel is running

This is the case that causes the most confusion. Your model opens the spreadsheet before the Excel application is launched. SpreadsheetOpen launches an Excel.exe process instance, and loads the model into that instance. The problem is that when you then launch the Excel application from Windows, it launches the Excel UI in a second Excel.exe process. If you attempt to open the model in that UI, it will inform you that the spreadsheet is already in use, and you'll only be able to open a separate copy, usually in read-only mode. This is usually not useful. Since it isn't the same instance of the spreadsheet, you cannot immediately view changes your model makes to the spreadsheet, etc.

The problem in this case occurs because there are two separate instances of Excel.exe running -- one in used by SpreadsheetOpen, and one in use by the Excel UI. You can verify this by looking at Task Manager's process view, where you'll see two Excel.exe process instances running. In order to view the same spreadsheet instance simultaneously, you need both to be using the same, single Excel.exe instance.

To my knowledge, it is not possible to start the Excel application UI from the Windows menus in such a way that it uses the currently running Excel.exe process instance. But it is possible to start it from Analytica as follows. From a button, or from the typescript window, evaluate:

SpreadsheetSetInfo( wb, 'Visible', true )

The Excel UI appears (using the same process in use by Analytica). Then select the View tab in Excel and Unhide on the toolbar ribbon, and select your spreadsheet.