WD97: No Toolbars When Word Doc Activated from VB OLE Container

Last reviewed: February 11, 1998
Article ID: Q176244
The information in this article applies to:
  • Microsoft Word 97 for Windows

SYMPTOMS

When you activate an OLE container as a Word Document object from within Microsoft Visual Basic, the Toolbars command on the View menu shows Standard, Formatting, and other toolbars selected. However, no toolbars display.

WORKAROUND

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

The following sample code makes all selected toolbars visible within an OLE container created in Microsoft Visual Basic.

Note: This example assumes you have already created a form in Microsoft Visual Basic and:

  • The form contains an OLE container that has its Class property set to a Word Document object (Word.Document.8).

    -and-

  • The form contains a command button.

    -and-

  • A reference to the Microsoft Office 8.0 Object Library has been set.

    Follow these steps to add the Microsoft Office 8.0 Object Library reference:

        1. On the Project menu, click References.
    

        2. Under Available References, click to select the "Microsoft Office
           8.0 Object Library" check box.
    

        3. Click OK.
    

For the purposes of this example, place the following code within the Click event procedure of the command button.

   Private Sub Command1_Click()

      Dim tbar As Object
      Dim iPrevBarPos As Integer

      OLE1.Action = 7

      ' Starts in-place activation for the object within the OLE container.
      Set tBar = OLE1.object

      ' Loop through each command bar to determine its visible attribute.
      For Each cBAr In tBar.CommandBars

         ' If the command bar should be visible...
         If cBar.Visible Then

            ' Make the command bar visible.
            ' NOTE: The Position property only works with the
            ' msoBarFloating constant in Visual Basic using in-place
            ' activation. All the other toolbar constants
            ' (msoBarTop, msoBarBottom, and so on) will not display the
            ' toolbar. Because of this, the toolbars cannot be docked
            ' within the OLE container.
            cBar.Position = msoBarFloating

            ' Sets the height of the specified command bar in pixels.
            cBar.Height = 25

            ' Sets the distance (in pixels) from the top edge of the
            ' specified command bar to the top edge of the screen.
            cBar.Top = iPrevBarPos + cBar.Height

            ' Get the top position of this bar to apply to height of next
            ' bar, so the command bars are stacked and not layered.
            iPrevBarPos = cBar.Top

            ' Sets the distance (in pixels) from the left edge of the
            ' specified command bar to the left edge of the screen.
            cBar.Left = 1

         End If

      Next

   End Sub

REFERENCES

For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q163435
   TITLE     : VBA: Programming Resources for Visual Basic for
               Applications


Additional query words: vba word8 word97 8.0
Keywords : kbcode kbprg kbwordvba
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbbug
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 11, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.