Solved

MSWord Viewer in VB App

Posted on 2001-07-17
9
520 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
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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 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

14 Experts available now in Live!

Get 1:1 Help Now