I have a requirement to move selected pages from word DocumentA into another word DocumentB. So in the end DocumentB should have its own contents plus selected pages from DocumentA inserted at selected pages in DocumentB. The page number in DocumentB I will set thru properties.
This is the code I am using to just append contents of DocumentA to 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;
}
However, I keep getting this exception 'object reference not set to instance of object' at the line 'selection.InsertFile...'
What is going wrong here?
And how do I insert contents of page 2 from DocumentA into page 3 of DocumentB?
Thanks for your time.