我爲Microsoft Office Word構建了一個加載項。當Word以管理員身份運行時,使用外接程序時沒有問題,但如果未以管理員身份運行Word,則存在兩個訪問功能區元素的常見異常。訪問COM組件時出錯
第一異常:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Core.IRibbonUI'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000C03A7-0000-0000-C000-000000000046}' failed due to the following error: could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND)).
at Microsoft.Office.Core.IRibbonUI.InvalidateControl(String ControlID)
當控制是通過下面的代碼無效發生此錯誤:
ribbon.InvalidateControl("control-id");
而第二個例外:
Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND)).
at Microsoft.Office.Interop.Word.ApplicationClass.get_Selection()
發生此錯誤在以下代碼的最後一行:
object wdStory = Word.WdUnits.wdStory;
object wdMove = Word.WdMovementType.wdMove;
WrdApp.Selection.EndKey(ref wdStory, ref wdMove)
我該如何解決這個問題?
它可以在其他計算機上工作嗎?我有一天打破了註冊表(在同事電腦上不少),並遇到類似於所有使用COM組件的程序的問題。如果它在另一臺計算機上工作,我會解釋我做了什麼來解決它。 – Wug
是的,在開發計算機上工作。只有在測試機器不工作。也許是因爲我安裝(和unistall)許多版本的Office(2007,2007-64,2010,2010-64) – Victor
哦,親愛的。那麼,測試機器運行什麼操作系統呢? – Wug