0

I was trying to automate office app in C# using Visual Studio. I opened the Word document using launch(@"WINWORD"), made some changes and saved the Word doc, and then closed the doc using process.kill().

Now next time, when I run the program, I look for all the office app and close them using process.kill. So in this case, one Word document was there, so it got closed as process.kill() finds it and close it. Then I did launch(@"WINWORD"), it opens the last saved word document. This is the problem, I want a fresh document to be opened.

When manually closing the Word using the close red icon, it functions properly. But with process.kill() I think it is saving the closed Word for next open.

Is there a way to close the Word document in a same way as we do by clicking on the red cross icon. So that a fresh word opens next time?

DecodeD
  • 7
  • 2

1 Answers1

0

process.CloseMainWindow(); solved my issues. It does close the Word document like we do manually and next time it opens a fresh.

Microsoft Document helped me: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.kill?view=net-5.0

DecodeD
  • 7
  • 2