none
How to Activate a Word document ? RRS feed

  • Question

  • I am creating word document from c# windows application. but Word document is getting minimized even though i used the Activate() method to activate the document.

    (it is working fine when debugging but in release version document getting minimized)

    How I Can Make the document active one???

    Thanks in advance.

    Tuesday, February 1, 2011 9:39 AM

Answers

  • Hi NiKnowJ

    I'm going to move this discussion to the Word Developer forum since you aren't using the VSTO technology. There are more people who understand Word, there, although most may not be working with it the way you're doing...

    I've been thinking about this for the past few days, hoping inspiration would strike, and all I come up with is:

    <<(it is working fine when debugging but in release version document getting minimized)>>

    Have you tried "releasing" this to various machines, with different configurations? I have never, in fifteen years, known Word to behave in this manner unless...

    there's a third-party software interfering and changing the window state mode.

    It coudl be something else - you don't show us all your code. Without seeing the variable declarations and object instantiations it's hard to be sure. But Word just doesn't behave like this "out-of-the-box".


    Cindy Meister, VSTO/Word MVP
    Monday, February 14, 2011 5:31 PM
    Moderator

All replies

  • look at

    ActiveWindow.State

    or something like that


    Visual Studio 2010 Professional, Office 2007
    Tuesday, February 1, 2011 9:42 AM
  • Hi NiKnowJ

    Is the user, or was the user or another application, working in minimized window state previously? Word will tend to open the next window in the same state as the last active window, which would explain why you're seeing this behavior. In that case, PetLahev is on the right track. But the command is:

    WordApplication.ActiveWindow.WindowState

    and this takes a WdWindowState Enum value


    Cindy Meister, VSTO/Word MVP
    Tuesday, February 1, 2011 10:07 AM
    Moderator
  • Hi Cindy Meister and PetLahev,

    Thank you for your reply,

    I checked application.ActiveWindow.WindowState, i am getting wdWindowStateMaximize

    but when I release the product I am getting minimized word document.

    There was no  previously minimized word document.

    I explicitly set the properties given below

    application.Visible = true;
    saveChanges = false;
    application.PrintPreview = true;//because i want application in print preview mode.
    application.Activate();
    

    Thanks in advance.

    Tuesday, February 1, 2011 12:18 PM
  • You also need to include setting the property for the window size in your code...
    Cindy Meister, VSTO/Word MVP
    Tuesday, February 1, 2011 4:38 PM
    Moderator
  • I still have the same problem.

    Am using Windows Vista, VS 2008 and Word 2007.

    The Word Document is blinking on the taskbar in minimized state.

     

    application.Visible = true;
    saveChanges = false;
    application.PrintPreview = true;
    application.WindowState = WdWindowState.wdWindowStateMaximize;
    application.Activate();
    

     

    But i couldn't find property to set window size. do you mean Width and Height properties ?

    Is it necessary to use the method like FindWindow() ,SetForegroundWindow() of user32.dll to make document active one.

    Any suggestion???

    Thanks In Advance.

    Wednesday, February 2, 2011 10:18 AM
  • Hi NiKnowJ

    I'm going to move this discussion to the Word Developer forum since you aren't using the VSTO technology. There are more people who understand Word, there, although most may not be working with it the way you're doing...

    I've been thinking about this for the past few days, hoping inspiration would strike, and all I come up with is:

    <<(it is working fine when debugging but in release version document getting minimized)>>

    Have you tried "releasing" this to various machines, with different configurations? I have never, in fifteen years, known Word to behave in this manner unless...

    there's a third-party software interfering and changing the window state mode.

    It coudl be something else - you don't show us all your code. Without seeing the variable declarations and object instantiations it's hard to be sure. But Word just doesn't behave like this "out-of-the-box".


    Cindy Meister, VSTO/Word MVP
    Monday, February 14, 2011 5:31 PM
    Moderator
  • Hi NiknowJ,

    I test my snippet in the environment your distributed, it works fine. I hope it helps.

    application.Visible = true;
    application.PrintPreview = true;
    application.ActiveWindow.WindowState = Microsoft.office.Interop.Word.WdWindowState.WdWindowStateMaximize;
    application.Active();
    

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 8, 2011 6:14 AM
    Moderator
  • Hi Tom,

    It is not work on C# 2010 + Window 7

    ("hope" in this case means not work).

    Please do not post an comment if it is not work on window 7, vista.

    + Windows Vista, VS 2008 and Word 2007.

    + Windows 7, VS 2010 and Word 2010.

    Hai.

    Thursday, July 19, 2012 2:43 AM