title: Excel Automation in WebBrowser Control
body: <p>I am using the following code to display an Excel Spreadsheet in a WebBrowser Control in VB.net 2010 Express.</p>
  
  <pre><code>Option Explicit On
  Imports Microsoft.Office.Interop
  Imports Microsoft.Office.Interop.Excel
  Imports Microsoft.Office.Core
  Imports System.Data
  Public Class CustomerService
        Dim oDocument As Object
        Dim oXL As Excel.Application
        Dim oWB As Excel.Workbook
        Dim oSheet As Excel.Worksheet
        Dim oRng As Excel.Range
        Private Sub CustomerService_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate(quoteFile)
  End Sub
  Private Sub WebBrowser1_NavigateComplete2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles WebBrowser1.NavigateComplete2
      On Error Resume Next
      Dim oXL As New Excel.Application
      oDocument = e.pDisp.Document
      With oDocument.Application.CommandBars("Standard")
          .Position = 4 '[msoBarFloating]
          .Visible = True
      End With
      MsgBox("File opened by: " &amp; oDocument.Application.Name)
      oDocument.Range("A1") = "HEllo"
  End Sub
  End Class
  </code></pre>
  
  <p>My question is, how can I reference the opened document in the WebBrowser1_NavigateComplete2 method so I can automate excel to say display text in a specific cell.</p>
  
  <p>Tried: </p>
  
  <pre><code>Option Explicit On
  Imports Microsoft.Office.Interop
  Imports Microsoft.Office.Interop.Excel
  Imports Microsoft.Office.Core
  Imports System.Data
  Public Class CustomerService
        Dim oDocument As Object
        Dim oXL As Excel.Application
        Dim oWB As Excel.Workbook
        Dim oSheet As Excel.Worksheet
        Dim oRng As Excel.Range
        Private Sub CustomerService_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate(quoteFile)
  End Sub
  Private Sub WebBrowser1_NavigateComplete2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles WebBrowser1.NavigateComplete2
      On Error Resume Next
      Dim oXL As New Excel.Application
      oDocument = e.pDisp.Document
      objApp = oDocument
      objBooks = objApp.Workbooks
      objBook = objBooks.Add
      objSheets = objBook.Worksheets
      objSheet = objSheets(1)
      oXL = oDocument(.Document) 'with or without .Document
      With oDocument.Application.CommandBars("Standard")
          .Position = 4 '[msoBarFloating]
          .Visible = True
      End With
      MsgBox("File opened by: " &amp; oDocument.Application.Name)
      objSheet.Range("A1") = "HEllo"
  End Sub
  End Class
  </code></pre>
  
  <p>With no luck. If you even have an inkling of a way to take this, I am all ears.</p>
  
  <p>Thanks</p>