What is the best way to display a Word document inside a visual basic application

I have a question that hopefully one of the experts on this message board can please answer for me.  I want to be able to store a Word document in a SQL Server database and retrieve it and display inside a Visual Basic 6 application with as minimal user steps and as cleanly as possible.  What is the best way to do this?  I have tried using the OLE control and it did not do what I want because it did not clip the document to the size of the OLE control for some reason when in view mode.  I tried to use the Web Browser control but it asked the user if he wanted to download the file and I dont know how to turn that off.  I tried using OLE Automation but I want the document to be inside the Visual Basic 6 application.  Is that possible?  I just want the user to be able to see the document, not edit it, and not be able to save the document or open another document using Word.  Any help on choosing the best method would be greatly appreciated.
Thanks,
Greg
gregoryewAsked:
Who is Participating?
 
edwardiiiConnect With a Mentor Commented:
The code I used to block user actions on my form's WebBrowser control is reliant on using FindWindow and FindWindowEx APIs to locate your VB form, then drill down to the WebBrowser you want to block.  If my code doesn't work for you, you'll need to use a tool like Spy++ that comes with C++ to get your VB app's structure.  The code below worked with a VBA Excel Userform that had a WebBrowser pointing to a FTP site. You'll likely have different class names.

Add the following to a module:

Public Declare Function EnableWindow Lib "user32" (ByVal hWnd As Long, ByVal cmd As Long) As Long
Public Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)
Public Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String)

To disable the WebBrowser window:

     Dim yourVbApp, vBAppLevel2, vBAppLevel3, vBAppLevel4 As Long
   
    yourVbApp = FindWindow(vbNullString, "Form1")
    vBAppLevel2 = FindWindowEx(yourVbApp, 0, "F3 Server 60000000", vbNullString)
    vBAppLevel3 = FindWindowEx(vBAppLevel2, 0, "Shell Embedding", vbNullString)
    vBAppLevel4 = FindWindowEx(vBAppLevel3, 0, "SHELLDLL_DefView", vbNullString)
   
    Call EnableWindow(vBAppLevel4, 0)

Also--there is no way to disable the "Enable macros" warning, unless you can digitally sign such documents, and every user of your VB app's machine has been setup to accept such DS documents as safe.

0
 
edwardiiiCommented:
Hi, gregoryew.

I tested setting Webbrowser1.navigate("myWordDoc.doc") with both files located on my desktop and files stored on our intranet document server.  In either case the only pop-up I got was when a Word document contained macros/vba.  Otherwise the Word docs displayed in the WebBrowser didn't allow users to open other instance of Word (e.g. the Word menu isn't displayed), and yes they could make edits, but when the WebBrowser control is closed no edits are saved.

For the popup you mention, possible entering WebBrowser1.Silent = True will do the job.  If you absolutely don't want users to be able to click anywhere in the Word doc (or type in it, etc.), I can give you some API code that would put a block over the entire WebBrowser control's surface area.  Let me know:)
0
 
Erick37Commented:
Is it possible to convert your documents to RTF, then use a locked RichTextBox to view the documents?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
gregoryewAuthor Commented:
Thanks for the responses but I am still having problems.  I tried to save the test document as rtf to make sure all macros were removed and open the file in the Web Browser control but I still got a similar error message which is "Some files can harm your computer.  If the file information below looks suspicious, or you do not fully trust the source, do not open or save this file."  I saved the file as a text document and opened it in the web browser control without a problem.  I even tried creating the document in word pad and still got the same problem.  I would rather not save the document as rich text because I want to store the document in the database and use words digital signature functionality which I dont think is available as a rich text format.  Also the code which edwardiii mentioned would be a good idea because I tried editting the document in the webbrowser control and it asked me if I wanted to save the document and the users could be confused by that.
Thanks,
Greg
0
 
Erick37Commented:
Did you try opening the RTF document in the Rich Textbox control instead?
0
 
gregoryewAuthor Commented:
Thanks for the help but as I previously stated I dont want to save the document in the RTF format because I would lose the digital signature functionality.  Also I would prefer not to save the document in two different formats like RTF and Word or HTML and Word but that maybe what I have to do.
Thanks,
Greg
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.