I have a working Excel COM library and I am trying to use the following method to determine if excel is in edit mode
public bool IsEditMode(Microsoft.Office.Interop.Excel.Application xlApp)
{
//https://stackoverflow.com/questions/464196/workaround-to-see-if-excel-is-in-cell-edit-mode-in-net
//xlApp = (Microsoft.Office.Interop.Excel.Application)ExcelDnaUtil.Application;
var bars = xlApp.Application.CommandBars;
var commandBar = bars["Worksheet Menu Bar"];
var menu = commandBar.FindControl(
1, //the type of item to look for
18, //the item to look for
Type.Missing, //the tag property (in this case missing)
Type.Missing, //the visible property (in this case missing)
true);
if (menu != null)
{
// Check if "New" menu item is enabled or not.
if (!menu.Enabled)
{
return true;
}
}
return false;
}
When my code hits xlApp.Application.CommandBars; I get the following exception.
System.Runtime.InteropServices.COMException: 'Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))'
I believe the issue is because I am referencing the wrong version of the office.dll. Either it is targeting the wrong version of office or the wrong version of Visual Studio.
My version numbers:
References I have tried
All three of these references give me the same exception. Any ideas how to load this?
The issue was with a typelib registration from a different version of Office. I ended up deleting registry entries for all versions of Office that were no longer installed.
These links gave me the info I needed to get it working.