想问问我程序那里有错啊?为什么查找替换不了啊?
(运行程序无报错现象, 但运行后无任何反应...)求大家帮帮忙啊~~~先谢谢了~~~
下面是除多余代码的全部代码....
报第37行出错,但doc 里面确实有find me这个词~~~
object miss = Type.Missing;
object visible = true;
object modify = false;
object filePath = "d:\\qbb.doc";
Word.Application app = new Word.Application();
public Form1()
{
InitializeComponent();
SearchReplace();
}
private void SearchReplace()
{
Word.Document doc = app.Documents.Open(ref filePath, ref miss, ref modify, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref visible, ref miss, ref miss, ref miss, ref miss);
doc.Activate();
try
{
object replaceAll = Word.WdReplace.wdReplaceAll;
app.Selection.Find.ClearFormatting();
app.Selection.Find.Text = "find me";
app.Selection.Find.Replacement.ClearFormatting();
app.Selection.Find.Replacement.Text = "Found";
app.Selection.Find.Execute(
ref miss, ref miss, ref miss, ref miss, ref miss,
ref miss, ref miss, ref miss, ref miss, ref miss,
ref replaceAll, ref miss, ref miss, ref miss, ref miss);
doc.Save();
}
catch (Exception e)
{
MessageBox.Show(Convert.Tostring(e), "错误", MessageBoxButtons.OK);
//return false;
}
finally
{
doc.Close(ref miss, ref miss, ref miss);
app.Application.Quit(ref miss, ref miss, ref miss);
}
}
http://msdn2.microsoft.com/zh-cn/library/f65x8z3d(VS.80).aspx 这里有例子,但是自己去做这个就出现问题,问题就是运行了没结果.... ....
望有心人帮帮忙啊~~ 先谢了!!!
[此贴子已经被作者于2007-10-24 22:43:37编辑过]