相互運用機能を介して Excel と対話する VB.NET で記述されたアプリケーションがあります。最終的に、セル編集モードの既知の問題に遭遇しました (背景については、 MSDNとstackoverflowを参照してください)。
提案されたコードを VB.NET に変換しようとしましたが、次のエラーが発生し続けます。
Reference required to assembly 'office, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' containing the type 'Microsoft.Office.Core.CommandBars'. Add one to your project. (BC30652) - E:\ ... .vb:3471
元の C# コード (前述の記事から) は次のとおりです。
private bool IsEditMode()
{
object m = Type.Missing;
const int MENU_ITEM_TYPE = 1;
const int NEW_MENU = 18;
// Get the "New" menu item.
CommandBarControl oNewMenu = Application.CommandBars["Worksheet Menu Bar"].FindControl(MENU_ITEM_TYPE, NEW_MENU, m, m, true );
if ( oNewMenu != null )
{
// Check if "New" menu item is enabled or not.
if ( !oNewMenu.Enabled )
{
return true;
}
}
return false;
}
私の変換されたVB.NETコードは次のとおりです
Private Function isEditMode() As Boolean
isEditMode = False
Dim m As Object = Type.Missing
Const MENU_ITEM_TYPE As Integer = 1
Const NEW_MENU As Integer = 18
Dim oNewMenu As Office.CommandBarControl
' oExcel is the Excel Application object
' the error is related to the below line
oNewMenu = oExcel.CommandBars("Worksheet Menu Bar").FindControl(MENU_ITEM_TYPE, NEW_MENU, m, m, True)
If oNewMenu IsNot Nothing Then
If Not oNewMenu.Enabled Then
isEditMode = True
End If
End If
End Function
Microsoft Office Object Library への (COM) 参照を追加しました
Imports Office = Microsoft.Office.Core
Imports Microsoft.Office.Interop
私はちょっと立ち往生しています。CommandBar オブジェクトを間接的に参照し、参照を再度追加しようとしましたが、何が問題なのかわかりません。何か案は?