none
Cómo utilizar el control WebBrowser para abrir un documento de Office en Visual Basic .NET RRS feed

  • Pregunta

  • Hola,

    Estoy viendo como abrir y manipular documentos del tipo Excel en Visual Studio 2012 con el código siguiente:

    Public Class Form1
    
        Dim oDocument As Object
    
        Private Sub Button1_Click(ByVal sender As System.Object, _
           ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim strFileName As String
    
            'Find the Office document.
            With OpenFileDialog1
                .FileName = ""
                .ShowDialog()
                strFileName = .FileName
            End With
    
            'If the user does not cancel, open the document.
            If strFileName.Length Then
                oDocument = Nothing
                AxWebBrowser1.Navigate(strFileName)
            End If
    
        End Sub
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As  _
           System.EventArgs) Handles MyBase.Load
    
            Button1.Text = "Browse"
    
            With OpenFileDialog1
                .Filter = "Office Documents " & _
                "(*.doc, *.xlsx, *.ppt)|*.doc;*.xlsx;*.ppt"
                .FilterIndex = 1
            End With
    
        End Sub
    
        Private Sub Form1_Closing(ByVal sender As Object, ByVal e As  _
           System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    
            oDocument = Nothing
    
        End Sub
    
        Private Sub AxWebBrowser1_NavigateComplete2(ByVal sender As Object, _
           ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event)
    
    
            On Error Resume Next
    
            oDocument = e.pDisp.Document
    
            'Note: You can use the reference to the document object to
            '      automate the document server.
            MsgBox("File opened by: " & oDocument.Application.Name)
    
        End Sub

     Estoy rompiéndome la cabeza donde esta el error pero no lo logro ver. Podeis ayudarme.

    Gracias

     

    domingo, 25 de mayo de 2014 15:22