Solved

MSWord Viewer in VB App

Posted on 2001-07-17
9
530 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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…

820 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