0

次のコードを使用して、VB.net 2010 Express の WebBrowser コントロールに Excel スプレッドシートを表示しています。

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: " & oDocument.Application.Name)
    oDocument.Range("A1") = "HEllo"
End Sub
End Class

私の質問は、WebBrowser1_NavigateComplete2 メソッドで開いているドキュメントを参照して、特定のセルにテキストを表示するように Excel を自動化する方法です。

試した:

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: " & oDocument.Application.Name)
    objSheet.Range("A1") = "HEllo"
End Sub
End Class

運がない。あなたがこれを取る方法を少しでも知っているなら、私はすべて耳を傾けています。

ありがとう

4

1 に答える 1