2016-11-10 66 views
0
try 
{ 
    Microsoft.Office.Interop.Word.Application WordObj = System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application") as Microsoft.Office.Interop.Word.Application; 
    Office.CustomXMLParts currClassification = WordObj.ActiveDocument.CustomXMLParts; 
} 
catch(Exception ex) 
{ 
    //I am getting, This command is not available because no document is open. this error here. 
} 

當我使用上面的代碼中,我得到這個錯誤:此命令不可用

This command is not available because no document is open.

問候

+0

,什麼是你的問題?錯誤消息中的某些內容不清楚? – arrowd

+0

實際上沒有文檔已經打開,我只需要獲取存儲在該文檔的元數據中的信息。 –

+0

對不起,但我沒有創建一個新的實例,我正在第一行中提取該單詞的當前活動實例。 –

回答

2

其實你正在努力在Word應用程序中沒有文檔打開時訪問活動文檔,以便發現錯誤。 您的單詞應用程序已打開,但未打開任何文檔,即您在圖像中顯示的單詞應用程序的主屏幕。

enter image description here

嘗試使用下面的代碼來檢查是否有您的應用程序的任何打開的文檔,然後訪問的ActiveDocument

if(WordObj.Documents.Count >= 1) 
相關問題