Solved

MSWord Viewer in VB App

Posted on 2001-07-17
9
524 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

770 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