程式上如果有錯誤的話,還是會有Exception的哦!
不過,word的alert也有可能不是Exception哦!
WdAlertLevel Enumeration : Specifies the way certain alerts and messages are handled while a
macro is running.
我試了一下,設了 DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
如果檔案有修改,WordApp.Quit(); 還是會Alert哦! 在寫程式時,請注意哦!
Microsoft.Office.Interop.Word.Application oAPP = new Microsoft.Office.Interop.Word.Application();
oAPP.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
try
{
oAPP.Documents.Add();
object start = 0;
object end = 0;
Microsoft.Office.Interop.Word.Range rng = oAPP.ActiveDocument.Range(ref start, ref end);
rng.Text = "New Text";
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
//設了 .DisplayAlerts 還是會 alert哦
oAPP.Quit();
}
亂馬客blog: http://www.dotblogs.com.tw/rainmaker/