Show TopMost Form in VSTO Without Document Losing Focus RRS feed

  • Question

  • I am working on a replacement for a Word 97 floating toolbar which got created at runtime from VBA code in a Word template.  The toolbar contained one button which added a paragraph to the Word document when clicked.  Before clicking the user had to place the cursor in the appropriate place.


    As floating toolbars no longer exist in Word 2007, I am looking to use a VSTO form with the .TopMost property set to True instead.  However, I am having trouble keeping the focus on the Word document when the form is loaded, which means you typically have to click in the main Word window twice in order to set the cursor to the appropriate place.


    I have overridden the form's ShowWithoutActivation property to return True but this does not appear to work in conjunction with .TopMost being True.  I am loading the form using the following code (after a custom ribbon is clicked):


    Dim objFrmPastePara As frmPastePara = New frmPastePara

    With objFrmPastePara

    .TopMost = True

    .ShowInTaskbar = False


    End With


    I have tried running Globals.ThisAddIn.Application.ActiveWindow.SetFocus() after this but to no avail.  How can the form be loaded without the document losing focus?

    Thursday, May 19, 2011 5:01 PM


All replies