Results 1 to 8 of 8

Thread: How to use the WebBrowser control to open an Office 2007 documents?

  1. #1
    Join Date
    May 2009
    Posts
    201

    How to use the WebBrowser control to open an Office 2007 documents?

    Hi everyone,
    I am having better knowledge of Visual Basic .NET. I want to use the web-browser control to open the documents that are created in Office 2007. I have tried lot of things but nothing worked for me. Maybe because I am not getting the logic properly. But I am sure that you guys must know it.!! So please explain me how to use the WebBrowser control to open an Office 2007 documents? Hope that you got my point.

  2. #2
    Join Date
    Aug 2006
    Posts
    181

    Re: How to use the WebBrowser control to open an Office 2007 documents?

    You may want to display or embed an Office document directly into a Visual Basic. NET. Unlike earlier versions of Visual Basic, Visual Basic. NET does not provide an OLE control that allows you to embed an Office document in a form. If you want to embed an existing document and open it as an ActiveX document in a Visual Basic. NET, you can use the Microsoft WebBrowser control. ActiveX documents are embeddable OLE objects that behave more like ActiveX controls than traditional OLE objects. Unlike a traditional embedded object, an ActiveX document is not intended to be an object within a larger document. It is rather considered a complete document is simply printed or collected into a single resource with other documents. An ActiveX document hosted in the WebBrowser control is always active and therefore, unlike traditional OLE embedded objects, place activation is meaningless.
    QTechnology Ultra-Quiet ATX PSU 460W I MSI K8N Neo4-F I AMD Opteron 144 CABNE0545 2.66Ghz I 2 x 512MB RAM I 380GB Maxtor SATAI Raid0 Hard Drive I 40GB Maxtor IDE Hard Drive I Nvidia GeForce 7900GTX I Win XP Home Service Pack 2 I Soundblaster Xtreme Fidelity Fatal1ty I Mercury Home Theater HT-4500

  3. #3
    Join Date
    Jul 2006
    Posts
    339

    Re: How to use the WebBrowser control to open an Office 2007 documents?

    To create a Visual Basic. NET opening Office documents, follow these steps :
    1. Create a new Windows Application project in Visual Basic. NET. Form1 is created by default.
    2. In the Tools menu, click Customize Toolbox to open the Customize dialog box tools. On the COM Components tab, add a reference to the Microsoft WebBrowser control. Click OK to add the WebBrowser control to the Toolbox Windows Forms. The WebBrowser control displays the text with Explorer in the toolbox.
    3. Using the toolbox, add a WebBrowser control, OpenFileDialog control and a button to Form1. This adds the member variables AxWebBrowser1, OpenFileDialog1 and Button1 to Form1 class.
    4. Define a private member in the Form1 class.
    5. Paste the following code in the Form1 class :
      Code:
      Option Explicit
      
      Dim oDocument As Object
      
      Private Sub Command1_Click()
         Dim sFileName As String
         
       ' Find an Office file...
         With CommonDialog1
            .FileName = ""
            .ShowOpen
            sFileName = .FileName
         End With
         
       ' If the user didn't cancel, open the file...
         If Len(sFileName) Then
            Set oDocument = Nothing
            WebBrowser1.Navigate sFileName
         End If
      End Sub
      
      Private Sub Form_Load()
         Command1.Caption = "Browse"
         ' For the 2007 Microsoft Office documents, change the .Filter parameter of the 
         ' With CommonDialog1 statement to:
         ' .Filter = "Office Documents " & _
         '      "(*.docx, *.xlsx, *.pptx)|*.docx;*.xlsx;*.pptx"
         With CommonDialog1
            .Filter = "Office Documents " & _
            "(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt"
            .FilterIndex = 1
            .Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly
         End With
      End Sub
      
      Private Sub Form_Unload(Cancel As Integer)
         Set oDocument = Nothing
      End Sub
      
      Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, _
      URL As Variant)
         On Error Resume Next
         Set oDocument = pDisp.Document
      
         MsgBox "File opened by: " & oDocument.Application.Name
      End Sub
    6. Press F5 to run the project. When you click Browse, the Open dialog box appears and allows you to go to a Word, Excel or PowerPoint. Select a file and click Open. The document opens in the WebBrowser control and a message indicating the server name of Office documents displayed.

  4. #4
    Join Date
    Aug 2006
    Posts
    209

    Re: How to use the WebBrowser control to open an Office 2007 documents?

    The WebBrowser control browses to documents asynchronously. When you call WebBrowser1.Navigate, the call returns control to your Visual Basic application before the document is fully loaded If you plan to automate the document content, you must use the event NavigateComplete2 to be informed of the late loading the document. Use the Document property of the WebBrowser object that is passed to obtain a reference to the subject of Office document that in the preceding code, is set to oDocument.
    Blessings to you

  5. #5
    Join Date
    May 2008
    Posts
    376

    Re: How to use the WebBrowser control to open an Office 2007 documents?

    The WebBrowser control mask usually docked toolbars before displaying an Office document. You can use Automation to display a floating toolbar with a code like this :
    Code:
    With oDocument.Application.CommandBars("Standard")
          .Position = 4 '[msoBarFloating]
          .Visible = True
       End With
    Newer versions of Internet Explorer (5.0 and later) also allow you to display docked toolbars using the following code :
    Code:
    ' This is a toggle option, so call it once to show the 
     ' toolbars and once to hide them. This works with Internet Explorer 5
     ' but often fails to work properly with earlier versions...
       WebBrowser1.ExecWB OLECMDID_HIDETOOLBARS, OLECMDEXECOPT_DONTPROMPTUSER

  6. #6
    Join Date
    May 2008
    Posts
    390

    Re: How to use the WebBrowser control to open an Office 2007 documents?

    There are several known issues in the presence of multiple WebBrowser controls in a project and the load of each control with the same type of Office document (ie, only Word documents or only Excel spreadsheets). It is recommended to use a single control project and browse to one document at a time. The most common problem relates to the Office command bars that appear disabled. If you have two WebBrowser controls on the same form, both loaded with Word documents, and you have displayed toolbars, one set of toolbars is active and functioning properly. The other is disabled and can not be used.

  7. #7
    Join Date
    May 2010
    Posts
    1

    Re: How to use the WebBrowser control to open an Office 2007 documents?

    Has anyone successfully tried loading/embedding Office 2010 docs in the WebBrowser control?

    For Office 2007, i managed to fix the problem thru this link:
    http://support.microsoft.com/kb/927009/en-us

    But now, I'm facing this problem of Office 2010 documents opening in a separate window, instead of being embedded on the form control.

  8. #8
    Join Date
    Oct 2004
    Posts
    1,342

    Re: How to use the WebBrowser control to open an Office 2007 documents?

    You can try to change the view settings for the file extension in Windows if the Word document opens in a new window rather than in the Web Browser control. Refer to the Ctrl-H help for the VIs for more information about setting the view settings for the .doc file extension. Download the embedword.zip.

Similar Threads

  1. Unable to open embedded PDF documents in excel 2007.
    By Zoello in forum Windows Software
    Replies: 5
    Last Post: 17-05-2011, 09:59 PM
  2. How to control WPF Webbrowser
    By Dharmesh Arora in forum Software Development
    Replies: 3
    Last Post: 13-07-2009, 09:58 AM
  3. Can't Open new Office format documents
    By Axton in forum Technology & Internet
    Replies: 4
    Last Post: 29-01-2009, 01:57 PM
  4. Convert Office 2003 documents to Office 2007
    By It Is Me Here in forum Vista Help
    Replies: 3
    Last Post: 08-05-2008, 01:15 AM
  5. Office Documents Slow to open on Double click.
    By Robbin M in forum MS Office Support
    Replies: 1
    Last Post: 14-12-2006, 04:58 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,486,766.06084 seconds with 17 queries