Solved

MSWord Viewer in VB App

Posted on 2001-07-17
9
512 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
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:PeteD
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:jtrapat1
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 8

Expert Comment

by:glass_cookie
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now