How can I make word visible when opening a document through interop?

10,240

Hmm. Apparantly both the application and the document has to be visible. So the solution is to add the line (before doc.Activate() ):

word.Visible = true;
Share:
10,240
Kasper Hansen
Author by

Kasper Hansen

Updated on July 05, 2022

Comments

  • Kasper Hansen
    Kasper Hansen almost 2 years

    I want to open a word document through interop and word must be visible in the process.It looks to be fairly straight forward because there is a parameter called "visible in the open function on a word document. But word is in the background. What am I missing?

    static void Main(string[] args)
    {
        Microsoft.Office.Interop.Word.Application word = null;
        word = new Microsoft.Office.Interop.Word.Application();
    
        object inputFile = "c:\\test.docx";
        object confirmConversions = false;
        object readOnly = true;
        object visible = true;
        object missing = Type.Missing;
    
        // Open the document...
        Microsoft.Office.Interop.Word.Document doc = null;
        doc = word.Documents.Open(
            ref inputFile, ref confirmConversions, ref readOnly, ref missing,
            ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref visible,
            ref missing, ref missing, ref missing, ref missing);
        doc.Activate();
    
        Console.ReadKey();
    }