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

ID: Q176244

The information in this article applies to:

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 professionals 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/

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:

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: wordcon vba word8 word97 8.0
Keywords          : kbcode kbprg kbwordvba 
Version           : WINDOWS:97
Platform          : WINDOWS
Issue type        : kbbug

Last Reviewed: April 5, 1999