How can we open the word documen on front of the main form?
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Word.Application oWord = new Word.Application();
Word.Document oWordDoc = new Word.Document();
oWord.Visible = true;
Object oTemplatePath = System.Windows.Forms.Application.StartupPath + "\\Sozlesme.docx";
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
Mehmet FatihPosted Jul 15, 2023, 1:12 PM
I have solved this problem by adding this code "oWord.ShowAnimation = true;"
Mehmet FatihPosted Jul 6, 2023, 9:01 PM
Normally, my codes are opening the word on the front of main form. But after after compiling the project it isn't opening on the front of the main form. Your codes are the same.
Deepak RawatPosted Jul 6, 2023, 4:47 PM
To open a Word document in front of the main form using C#, you can follow these steps:
Ensure you have added the necessary references to your project. Right-click on your project in Visual Studio, select "Add" -> "Reference", and then browse and select the "Microsoft.Office.Interop.Word" assembly.
Import the required namespaces at the top of your code file:
In this code, we create a new instance of the
Word.Applicationobject, set itsVisibleproperty totrueto make the Word application window visible, and then provide the path to the Word document using thetemplatePathvariable. Finally, we use theDocuments.Add()method to open the document in the Word application.Make sure to adjust the
templatePathvariable to the correct path and filename of your Word document.Mehmet FatihPosted Jul 6, 2023, 2:05 PM
Thanks for your intrest Mohamed, I have tried y our codes but it gives an error in the other codes. All I want is to open a word document on the top of main form as in the picture.
Mohamed Azarudeen ZPosted Jul 6, 2023, 12:14 PM
Hi Mehmet
1.To open a Word document in front of the main form, you can follow these steps:
2.Create an instance of the Word Application:
3.Set the visibility of the Word Application to true:
4.Open the Word document and assign it to a Document object:
Here's the updated code snippet: