Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

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.

What I have tried:

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();
Posted
Updated 22-Feb-18 21:19pm

Quote:
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.


Sorry, but you're wrong!
You did not specify what you mean by saying "can't seem to get that to work" and you didn't provide information about error message. Nevertheless...
The reason you can't get it to work is quite obvious... The problem is laying in here:
C#
doc.Activate();


You can't activate a document (move focus to it) when hosting application is invisible. Remove every line which uses methods: Activate() and Select() and everything should start working.
 
Share this answer
 
try this way , this works for me

C#
// Create an Application object

Microsoft.Office.Interop.Word.ApplicationClass ac = new Microsoft.Office.Interop.Word.ApplicationClass();

Microsoft.Office.Interop.Word.Application app = ac.Application;

app.DisplayAlerts = Microsoft.Office.Interop.Word.

WdAlertLevel.wdAlertsNone;

object filename = strFileName;

object missingValue = Type.Missing;

app.Visible = true;

Microsoft.Office.Interop.Word.

Document document = app.Documents.OpenOld(ref filename,ref missingValue, ref missingValue,ref missingValue, ref missingValue, ref missingValue,ref missingValue, ref missingValue, ref missingValue, ref missingValue);

app.Activate();

}
 
Share this answer
 
Comments
Maciej Los 23-Feb-18 3:20am    
OP is trying to move focus to the document which is hosted in invisible application. Please, see my answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900