Below i attached my project, where i want to open a document file(which is also attached) with read and write access, by clicking open button and "EditDocument" form will also open. whatever i will write in textbox1 in "EditDocument" form, it will replace it with "Name" in word document.
textbox2.text will replace it with "Address" in word document.
textbox3.text will replace it with "Qualification" in word document.
"It will act like find and replace option in office2007".
can onyone help me on this problem.
Loading


Iftikar HussainRank #423 · 5.9K reputationPosted Aug 5, 2013, 10:20 PM EDT
I have modified your project, please find the attached.
You need to set the template path
Regards,
Iftikar
Posted Aug 5, 2013, 10:18 PM EDT
it will open in a separate process in that you can't do Find & replace.
Instead of that, launch word in your application, do the find & replace.
The code looks something similar to this.
It will write some text into the word document and you can try for find & replace here.
private void button1_Click(object sender, EventArgs e)
{
object missing = System.Reflection.Missing.Value;
object Visible=true;
object start1 = 0;
object end1 = 0;
ApplicationClass WordApp = new ApplicationClass();
Document adoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
Range rng = adoc.Range(ref start1, ref missing);
try
{
rng.Font.Name = "Georgia";
rng.InsertAfter("Hello World!");
object filename = "YOUR DOCUMENT PATH";
adoc.SaveAs(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
WordApp.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Preeti AgrawallaRank #6,677 · 259 reputationPosted Aug 5, 2013, 11:31 PM EDT
Iftikar, this error i am getting.
Preeti AgrawallaRank #6,677 · 259 reputationPosted Aug 5, 2013, 11:36 PM EDT
Posted Aug 5, 2013, 11:40 PM EDT
Document adoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
Range rng = adoc.Range(ref start1, ref missing);
Posted Aug 5, 2013, 11:41 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 5, 2013, 11:44 PM EDT
Regards,
Iftikar
Preeti AgrawallaRank #6,677 · 259 reputationPosted Aug 5, 2013, 11:47 PM EDT
Preeti AgrawallaRank #6,677 · 259 reputationPosted Aug 6, 2013, 12:03 AM EDT
Preeti AgrawallaRank #6,677 · 259 reputationPosted Aug 6, 2013, 12:07 AM EDT
Posted Aug 6, 2013, 12:16 AM EDT
doc.SaveAs("MyFile.doc", ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 6, 2013, 12:47 AM EDT
Regards,
Iftikar