選択したページを Word DocumentA から別の Word DocumentB に移動する必要があります。したがって、最終的に DocumentB には独自のコンテンツと、DocumentB の選択されたページに挿入された DocumentA から選択されたページが含まれている必要があります。DocumentB のページ番号は、プロパティで設定します。
これは、DocumentA のコンテンツを DocumentB に追加するために使用しているコードです。
object missing = System.Reflection.Missing.Value;
Word._Application wordApp = new Word.Application();
Word._Document aDoc = new Word.Document();
try
{
wordApp.Visible = false;
object readOnly = false;
object isVisible = false;
aDoc = wordApp.Documents.Open(ref fPath1, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
Word.Selection selection = wordApp.Selection;
selection.InsertFile(fPath2, ref missing, ref missing, ref missing, ref missing);
aDoc.Save();
wordApp.Quit(ref missing, ref missing, ref missing);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
wordApp = null;
aDoc = null;
}
ただし、「selection.InsertFile...」行で「オブジェクト参照がオブジェクトのインスタンスに設定されていません」という例外が引き続き発生します。
ここで何がうまくいかないのですか?
DocumentA のページ 2 のコンテンツを DocumentB のページ 3 に挿入するにはどうすればよいですか?
御時間ありがとうございます。