[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2005-04-12
6
Medium Priority
?
276 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:gregoryew
  • 2
  • 2
  • 2
6 Comments
 
LVL 10

Expert Comment

by:edwardiii
ID: 13764778
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
 
LVL 32

Expert Comment

by:Erick37
ID: 13765182
Is it possible to convert your documents to RTF, then use a locked RichTextBox to view the documents?
0
 

Author Comment

by:gregoryew
ID: 13765818
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 32

Expert Comment

by:Erick37
ID: 13765982
Did you try opening the RTF document in the Rich Textbox control instead?
0
 

Author Comment

by:gregoryew
ID: 13766309
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
 
LVL 10

Accepted Solution

by:
edwardiii earned 2000 total points
ID: 13767156
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

834 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