2012-03-23 72 views

回答

5

這應該做

if (string.IsNullOrEmpty(WordInstance.ActiveDocument.Path)) 
    { 
     throw new ApplicationException("Document must be saved first"); 
    } 
+0

+1真的很聰明! – Sabuncu 2013-08-16 16:55:42

1

爲VSTO開發人員,請到這裏

if (Globals.ThisAddIn.Application.ActiveDocument.Path == String.Empty) 
    { 
     Word.Dialog dlg; 
     Object timeout = 3000; 
     dlg = Globals.ThisAddIn.Application.Dialogs[ 
      Word.WdWordDialog.wdDialogFileSaveAs]; 
     int result = dlg.Display(ref timeout); 
    } 
    else 
    { 
     Globals.ThisAddIn.Application.ActiveDocument.Save(); 
    } 

結果將存儲在按下哪個按鈕(0-取消,1- OK,2-接近)

+0

這是舊版本嗎?至少對於Word 2010來說,返回的數字不正確,確定爲-1(實際上應該是枚舉),並返回0以表示任何類型的取消。無論如何,所有保存對話信息都與問題無關。 – Chris 2016-04-17 17:57:20