私はC#のランク初心者です。現在、Visual Studio 2015を使用してWord 2013のリボンベースのVSTOプラグインを作成していますWord 2013 VSTOプラグインでApplication.Select.Findを利用できません
- ユーザーからの入力をテキストボックスに入力します。
- 一連の文字( "xxxxx")を検索し、以前のユーザー入力を使用してドキュメント全体のセットを置き換えます。
- 文書をPDFとして保存します。
私は現在、罰金最初と最後タスクを実行することができています。皮肉なことに、私はMSDN article on Find & Replaceからコードを直接使用しましたが、私のビルドを妨げるエラーが発生し続けます。私は、Application.Selection.Find
をWord.Selection.Find
と置き換え、WordApp.Selection.Find
と置き換えることを含む多くの解決策を試したが、役に立たなかった。次のように
私の正確なエラーは:「 エラーCS0117 『アプリケーション』 『選択』の定義が含まれていません」私はそれが私にバティを駆動しています、ここでの勝利に近い感じ
を。私は以下の完全なコードを投稿しました。
ご協力いただきありがとうございました。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
using Microsoft.Office.Tools.Word;
namespace RestRef_Automator_Test
{
public partial class Ribbon1
{
private bool flag;
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
//Get, Find, & Replace RID
int myRID = 0;
string myString = myRID.ToString();
flag = int.TryParse(RID.Text, out myRID);
if (flag == false)
{
MessageBox.Show("Please enter in a number.", "Input Error");
return;
}
Word.Find findObject = Application.Selection.Find;
findObject.ClearFormatting();
findObject.Text = "xxxxx";
findObject.Replacement.ClearFormatting();
findObject.Replacement.Text = myString;
object replaceALL = Word.WdReplace.wdReplaceAll;
object missing = null;
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);
//Save as PDF w/ applicable name.
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = "*";
dlg.DefaultExt = "pdf";
dlg.ValidateNames = true;
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{ Globals.ThisAddIn.Application.ActiveDocument.ExportAsFixedFormat(dlg.FileName, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF, OpenAfterExport: true); }
}
}
}
まだ関連しています。しかし、ある時点でCS0117を取得したことを覚えています。 [this](https://support.microsoft.com/en-us/kb/821175)ページで解決しました。 –
@NickOtten、ありがとう!とても有難い。残念ながら、私のスキルレベルはかなり低いので、上記のコードでどのように実装されるかを理解するのに少し問題があります。あなたは時間があれば、私は上記の使用例を求めてもいいですか?そうでなければ、全く問題ありません!ありがとうございました! –
私は別の何かに気付いたときに私は例を作っていました、下記の答えを見てください。 –