我最近开始学习C#。 我正在尝试用C#编写一些我的宏(用VBA编写) - 实际上我正在尝试使用按钮做一些活动来为Word创建一个新的功能区... 所以,我正在尝试在活动文档中创建一个简单的查找/替换按钮。 我从Microsoft站点复制了这段代码,但它仍然强调单词MISSING:
public void button1_Click(object sender, RibbonControlEventArgs e){
Word.Find findObject = Globals.c_sharp.Application.Selection.Find;
findObject.ClearFormatting();
findObject.Text = "find me";
findObject.Replacement.ClearFormatting();
findObject.Replacement.Text = "Found";
object replaceAll = Word.WdReplace.wdReplaceAll;
findObject.Execute(ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref replaceAll, ref missing, ref missing, ref missing, ref missing);
}
这里有什么问题?
答案 0 :(得分:0)
Type.Missing
。在当前版本中,它可以简化:
Globals.c_sharp.Application.ActiveDocument.Content.Find.Execute("find me",
Format: false, ReplaceWith: "Found", Replace: Word.WdReplace.wdReplaceAll);