Search code examples
c#ms-wordexcel-2007office-interop

How do I hide Word and Excel from displaying on screen in C#


I am trying to hide Word and Excel from displaying when I am processing some documents. I know it is capable of not even being displayed on the taskbar but hidden as a process but I can't seem to get that to work. I am also not sure if creating excel tables or charts is causing this problem as well.

Any advice is appreciated. Thank you.

Here is a code fragment that I currently have.

object missing = System.Reflection.Missing.Value;
object readOnly = true;
object addToRecentFiles = false;
object visible = false;

object filename = Path.Combine(Directory.GetCurrentDirectory(), "Lorem ipsum dolor sit amet.docx");

Word.Application word = null;
word = new Word.Application();
word.Visible = false;

Word.Documents documents = word.Documents;
Word.Document doc = documents.Open(ref filename, ref missing, ref readOnly, ref addToRecentFiles, ref missing, ref missing, true, ref missing, ref missing, ref missing, ref missing, ref visible, ref missing, ref missing, ref missing, ref missing);
doc.Activate();

Solution

  • try adding the last line .DisplayAlerts = false; I have here to both your docs you've made there:

    Word.Application word = null;
    word = new Word.Application();
    word.Visible = false;
    word.DisplayAlerts = false;