addin excel RRS feed

  • Question

  • j'ai trouvé ce probléme lorsque j'ai fait ce code dans mon addin excel avec vb net 

    Code : 

     Private Sub ThisAddIn_Startup(ByVal sender As Object, _
                      ByVal e As System.EventArgs) Handles Me.Startup
            appExcel = Application
            ' Dim oWS As Excel.Worksheet = Globals.ThisAddIn.Application.ActiveSheet
            Dim sheet As Excel.Worksheet = CType(Globals.ThisAddIn.Application.ActiveSheet, Excel.Worksheet)
            sheet.SelectionChange = New Excel.DocEvents_ChangeEventHandler( _
                AddressOf sheet_SelectionChange)

        End Sub
        Public Sub sheet_SelectionChange(ByVal Target As Excel.Range)

        End Sub

    Error :Public member 'SelectionChange' on type 'Worksheet' not found.

    Please can you help me.

    Wednesday, June 4, 2014 10:06 AM


  • Hi fatma

    A VSTO add-in works a bit differently than a document-level customization or VBA. You aren't going to be able to create an event on the specific sheet, only on the application, as in the code sample below. You'll find more information on how to generate code stubs for events at

    Public Class ThisAddIn
        Private Sub ThisAddIn_Startup() Handles Me.Startup
        End Sub
        Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
        End Sub
        Private Sub Application_SheetSelectionChange(ByVal Sh As Object, _
    ByVal Target As Microsoft.Office.Interop.Excel.Range) _
    Handles Application.SheetSelectionChange MessageBox.Show("Changed!") End Sub End Class

    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, June 4, 2014 4:08 PM

All replies