Error Activating Word Application

I have some code that will run on a server and will generate a word file, to be downloaded to the user.  Since it is running on a server, there is no good reason to have the Word application itself visible.  The trouble is that I cannot activate Word when I set visible to false.

The code below works fine.

When I comment out the line that says 'mswApp.Vislble = true", I get a COMError that it cannot activate the application.

Any idea why?  Why would it let me set the application to invisible if I cannot activate it once I do?

Thanks.



mswApp = new Microsoft.Office.Interop.Word.Application();
mswApp.Visible = false;
//
// Comment out the next line for production
//
mswApp.Visible = true;
mswApp.Activate();

Open in new window

TimAttawayAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
>>Any idea why?

Well activate gives it the focus - oops, it's hidden !!
0
 
TimAttawayAuthor Commented:
Ah!  I thought you had to activate the application before you could generate a document but in fact you don't.  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.