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://stackguides.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:
- VS 2017 Community (15.8.6)
- Excel 2010 Office Standard 32-bit (14.0.7214.5000)
References I have tried
- Manually add reference to C:\Windows\assembly\GAC_MSIL\office\14.0.0.0__71e9bce111e9429c\OFFICE.DLL
- Let visual studio add the reference automatically to C:\Program Files (x86)\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA\Office14\office.dll
- VS Reference Manager -> COM -> Microsoft Office 14.0 Object Library. (C:\WINDOWS\assembly\GAC_MSIL\Office\15.0.0.0__71e9bce111e9429c\Office.dll)
All three of these references give me the same exception. Any ideas how to load this?