2012-07-16 37 views
1

我需要在Word中禁用SaveAs或防止用戶更改文件名。在Word中禁用SaveAs

我的應用程序允許用戶使用頭文件我爲它們提供程序創建一個MailMerge文檔。當用戶只是簡單地保存並退出Word時,此功能就可以工作。如果用戶另存爲,應用程序將被鎖定。我正在使用Microsoft.Office.Interop.Word

//MyWordApp & doc is initialized. 

MyWordApp.Application.Visible = true; 

While(WordIsOpen())//Holds execution here while User is editing in Word 
{ 
} 

WordIsOpen定義:

public bool WordIsOpen() 
{ 
     if (MyWordApp.Application.Visible)//Locks up here 
     { 
      return true; 
     } 
     else 
      return false; 
} 

禁售:

//I have a BeforeSave event that Saves the doc and quits Word 

DocumentBeforeSave(Doc, SaveAsUI, Cancel) 
{ 
     //Save Doc 

     MyWordApp.Quit(ref objFalse, ref objNull, ref objNull);//Also, Locks up here 
} 
+5

爲什麼不修復它,使應用程序不鎖定? – Ghost 2012-07-16 20:10:58

+4

確定爲什麼應用程序鎖定並解決該問題不是更有意義嗎? – CaffGeek 2012-07-16 20:11:05

+0

我試過修復它。我改變了我一直在做的方式。走完整個圈子,最後回到你在這裏看到的方法。 – ExceptionLimeCat 2012-07-16 20:39:17

回答

1

我不能完全知道是什麼引起的,最終這個問題。我確定它與COM行爲有關。在調試模式下使用Word Interop時存在已知的錯誤。我遇到的唯一方法可能可以解決此問題,即攔截在SaveAs之前或之後發生的COM事件。我沒有實施這個解決方案,所以我不知道那是什麼。

相關問題