Solved

MSWord Viewer in VB App

Posted on 2001-07-17
9
542 Views
Last Modified: 2011-10-03
Can anyone suggest something for my program?
I'm using VB6 against an SQL Server database.
I have a form which brings up a MSWord document.
I need to have the document readable, not editable.
Also,the document must be read-only.
Also, I don't need any toolbars, rulers,etc.

Currently, I'm using an OLE object to display the MSWord document.  But I had problems adding scroll bars to allow the user to view the entire document.

I tried several things: The Browser Control,but it offered too much - tool bars,etc.
I tried the Oframer example project from Microsoft,but it too gave me too much on the form.
And,with the current OLE object,I can't get rid of the rulers when I display a MSWord object inside the OLE container.

I need something like the word viewer on a form.
It should be a viewer, no toolbars, rulers, etc.
Just present the document to the user in read-only form.

Any suggestions?
Thanks
John
0
Comment
Question by:jtrapat1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:PeteD
ID: 6291913
I guess, something like:Dim objW As Object

Option Expicit

Dim objDoc As Object
Dim nCnt As Integer

Private Sub Form_Load()
    Set objW = CreateObject("word.application") ' true for readonly
    Set objDoc = objW.Documents.Open("c:\mydoc", , True)
    On Error Resume Next
    For nCnt = 1 To objW.CommandBars.Count - 1
        objW.CommandBars(nCnt).Visible = False
    Next
    objW.CommandBars.ActiveMenuBar.Enabled = False
    objW.Visible = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
    On Error Resume Next
    objDoc.Close
    objW.Quit
    Set objW = Nothing
    Set objDoc = Nothing
End Sub


0
 
LVL 2

Accepted Solution

by:
PeteD earned 200 total points
ID: 6291914
oops I meant:

Dim objW As Object
Dim objDoc As Object
Dim nCnt As Integer

Private Sub Form_Load()
    Set objW = CreateObject("word.application") ' true for readonly
    Set objDoc = objW.Documents.Open("c:\mydoc", , True)
    On Error Resume Next
    For nCnt = 1 To objW.CommandBars.Count - 1
        objW.CommandBars(nCnt).Visible = False
    Next
    objW.CommandBars.ActiveMenuBar.Enabled = False
    objW.Visible = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
    On Error Resume Next
    objDoc.Close
    objW.Quit
    Set objW = Nothing
    Set objDoc = Nothing
End Sub
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6293947
Hi!

Here's a file over the net for you:

Download...
http://www.vb-helper.com/Howto/word2txt.zip

Description: Translate a Word file into a text file (8K)

AND

Download...
http://www.vb-helper.com/Howto/footers.zip

Description: Open Word files and add footers giving their file names (10K)

That's it!

glass cookie : )
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:jtrapat1
ID: 6294326
Pete,
That code worked great and did exactly what I wanted.
I thought you could only use that type of code in .asp.

The only other thing I'd like to do is maybe put that word document in its own container on a form if possible.
Do you know if there is any way to do this?
If not, that's ok; I'll try to find some workaround.

Here's more detail:
On the form, we have a textbox in which the user can search for a particular bill (by number) from a sql server database.  There's a tabbed dialog box, so the user can select one tab which will show them the contents of the written bill in a read-only window, without any types of formatting toolbars.
If, the user wishes to edit the document, there's a command button to the right, which will open the document in its own msword environment.

Thanks again for the help.

Also, thanks glass_cookie for the two files.
I'll check them out now -
I've been trying everything.

Thanks again
John
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6294773
For the code Description: Translate a Word file into a text file (8K), you might want to convert it to a text file then load it.

That's it!

glass cookie : )
0
 

Author Comment

by:jtrapat1
ID: 6295417
Pete,
Just one more question.
For this code segment:
   
   For nCnt = 1 To objW.CommandBars.Count - 1
       objW.CommandBars(nCnt).Visible = False
   Next
   objW.CommandBars.ActiveMenuBar.Enabled = False

When you're looping thru to take off the toolbars, it doesn't get rid of the ruler or the layout buttons at  the bottom.
Is there any way to get rid of the ruler?
I checked windowstate and activemenubar is disabled and it still shows up.
Because, if the ruler is there, the user can right-click and change the layout.

I'd like to disable this if possible.

Thanks again for all the help.
John
0
 
LVL 2

Expert Comment

by:PeteD
ID: 6301747
to disable the ruler:

objW.CommandBars.ActiveMenuBar.Controls(3).Controls(6).Visible = False


I recommend putting a breakpoint in your code after objW has been created, then add a watch on objW and explore the object in the watch window! You will learn a great deal this way!

0
 

Expert Comment

by:ComTech
ID: 6532884
Will be an 50/50 split. I will reduce the points to 100 to accept one answer here, and create another fro the other Expeert in this question.

PeteD will bee accepted here for 100 points and will created a questin in this TA for glass_cookie..

Regards,
ComTech
Community Support
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6533080
Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question