VB3 How to Scroll an Embedded Word 6 Document in VB OLE

Last reviewed: January 9, 1997
Article ID: Q118646
The information in this article applies to:
  • Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0
  • Microsoft Word for Windows, version 6.0

SUMMARY

Word for Windows version 6.0 does not supply scroll bars that would allow an activated document embedded in the Visual Basic 3.0 OLE container control to be scrolled through. This article describes how to provide buttons that allow the user to scroll through an embedded Word for Windows version 6.0 document that has been activated for visual editing.

To scroll through the window, you must call a Word Basic method such as VLine. However, if you call the method from within a scroll-bar event, the code does not work. The problem is that when the scroll bar receives the focus, the Word document object in the OLE control is deactivated. If you try to activate the Word Document object in the scroll-bar event, the insertion point moves to the beginning of the document, causing you to lose the current position in the document. This problem happens with any control that can receive the focus.

MORE INFORMATION

To work around the problem, use a control that cannot receive the focus (for example, the image-control or the spin button). You can use the image control to simulate a button. When you click it, the focus remains on the OLE container control, and therefore the Word document object stays activated. This allows you to call a Word Basic method such as VLine to allow you to scroll through the window in the click event of the image control.

Example

  1. Start Visual Basic; Form1 is created by default.

  2. Add an OLE container control to Form1 (Ole1 is the default name for the control).

  3. The insert object dialog box should appear after you draw the OLE container control on the form. Choose Create from the File option, and choose an existing Word .DOC file that is more than a page in length. The "Link" and "Display As Icon" check boxes should not be checked. Choose the "OK" button when you are done; the document should now be embedded in the OLE container control.

  4. Add a spin button to Form1 (Spin1 is the default name of the control).

  5. Place the following code in the spin-down event:

          Sub Spin1_SpinDown ()
             If Ole1.AppIsRunning Then
                Ole1.Object.Application.WordBasic.VLine 1
             Else
                Ole1.Action = 7 'Activate
             End If
          End Sub
    
    

  6. Place the following code in the spin-up event.

          Sub Spin1_SpinUp ()
             If Ole1.AppIsRunning Then
                Ole1.Object.Application.WordBasic.VLine -1
             Else
                Ole1.Action = 7 'Activate
             End If
          End Sub
    
    

  7. Save the project.

  8. Run the application.

  9. Double-click the OLE control to activate the Word .DOC object for visual editing.

10.Press the spin button to scroll up and down the document.

Notes

  • You can speed up the scrolling by changing the delay property on the spin button. You can also change the number of lines that the VLine method scrolls through.
  • Some other controls that do not receive the focus are the shape, line, frame, 3D frame, 3D panel, and label controls.


KBCategory: kbole kbprg kbcode
KBSubcategory: IAPOLE
Additional reference words: 3.00 scrollbar



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: January 9, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.