Link to home
Start Free TrialLog in
Avatar of jtrapat1
jtrapat1

asked on

Adding Scroll Bars To Word in OLE Container

I'm using VB6 against an SQL Server 7 database and am trying to do the following:

I'm using an OLE container to display MS Word documents on a form.
When the user double-clicks on the container, I open the MSWord document in its own window so the user can edit it there.
However, the users would like to have the ability to scroll in the container window.
I guess this can't be done directly since scroll bars are not a property of the OLE object.
I'm trying to find info on this and I found what may be an option:
Someone suggested the webbrowser control which was added with sp4.
With this control, many of the word features can be used inside the container.
This may be too much for what I want to do, though.
Remember, I just need to give the user the ability to scroll up and down in a word document.
Does anyone have any experience with the webbrowser control and word documents?
Can anyone suggest any alternatives or suggestions for what I want to do?

Thanks in advance.
John
Avatar of terry_mtw
terry_mtw
Flag of United States of America image

yep, this is not supply scroll bars,  so, if you want to scroll the document, you should use spin button or image-control that cannot receive the focus.

Sub SpinButton1_SpinDown()
    If OLE1.AppIsRunning Then
        OLE1.object.Application.WordBasic.vline 1
    Else
        OLE1.Action = 7     ' Activate
    End If
End Sub

Private Sub SpinButton1_SpinUp()
    If OLE1.AppIsRunning Then
        OLE1.object.Application.WordBasic.vline -1
    Else
        OLE1.Action = 7     ' Activate
    End If
End Sub
Avatar of jtrapat1
jtrapat1

ASKER

terry,

thanks for the info.
can you just let me know one more thing?
When you first add an OLE object to a form, you are prompted if you want to create a link to an existing word document (or other file).
When I choose to link to an existing word doc, the code for the scroll bars above works.
However, if I try to pass the OLE object a filename, and have the OLE object link to that document on the fly, it doesn't work.
If I then move the scroll bars, it simply opens up MSWord with that document inside.

here's the code I tried:
    If Dir(FileName) <> "" Then
        OLE1.CreateLink FileName
    Else
        OLE1.CreateLink "z:\FILE\template.doc"      
    End If
   
Is there a way around this?

Thanks
hihi,
if you want to embed a document to your ole container, you can use OLE1.CreateEmbed "filename or path". Then, add OLE1.DoVerb -1 comment to activate and edit the document.

Following is the example to embed the Hi.doc in c directory and scroll the ole container.
Hope this can help you.....^^

start vb and standard form, and add ole1 and don't insert object. then add command1 and timer1 and name it OleTimer.

Option Explicit

Dim oleActive As Boolean
Dim oleFileName As String

Private Sub form_load()
    oleActive = False
End Sub

Private Sub OleTimer_Timer()
    If oleActive Then
    With OLE1.object
        .ActiveWindow.DisplayVerticalScrollBar = True
        .ActiveWindow.DisplayHorizontalScrollBar = True
    End With
    End If
End Sub

Private Sub Command1_Click()
    OLE1.CreateEmbed "c:\HI Terry1.doc"
    OLE1.DoVerb -1
    OLE1.SizeMode = 1
    oleActive = True
End Sub


ASKER CERTIFIED SOLUTION
Avatar of terry_mtw
terry_mtw
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial