WorkbookOpen Event not working

37 views
Skip to first unread message

Rich Russell

unread,
May 7, 2022, 8:53:38 AMMay 7
to Excel-DNA
I'm trying to get the WorkbookOpen Event to fire so I can run code when a new workbook is opened.  Below is the code I'm using and I get a compile error in the highlighted 2 lines.  I cannot determine the underlying issue resulting in the compile errors.  I'm using VB.net

Any help will be appreciated.

Rich

Imports Microsoft.Office.Interop.Excel      
Imports ExcelDna.IntelliSense
Imports ExcelDna.Integration
Imports ExcelDna.Integration.ExcelDnaUtil    


Public Class ClsAddIn

    Implements IExcelAddIn
    Dim applicationEvents As EventTest

    <ExcelCommand()>
    Sub Start() Implements IExcelAddIn.AutoOpen
        IntelliSenseServer.Install()

        applicationEvents = New EventTest
        'bhm2 =
    End Sub

    Sub Close() Implements IExcelAddIn.AutoClose
        IntelliSenseServer.Uninstall()
    End Sub

    Public Shared Sub Sub_SelectList()
        Dim SelectForm As New Form_Select
        SelectForm.ShowDialog()
    End Sub

    Public Shared Sub Sub_ErrorMessaging()
        Dim SelectForm1 As New Form_ErrorMessaging
        SelectForm1.ShowDialog()
    End Sub

    Public Shared Sub Sub_FunctionHelp()
        Dim SelectForm2 As New Form_FunctionHelp
        SelectForm2.Show()
    End Sub

End Class

Public Class EventTest

    Dim WithEvents AppEve As application

    Public Sub New()
        AppEve = ExcelDnaUtil.Application
    End Sub

    Private Sub AppEve_WorkbookOpen() Handles AppEve.WorkbookOpen
        MsgBox("Opened workbook: ")
    End Sub

End Class

Rich Russell

unread,
May 14, 2022, 7:11:22 AMMay 14
to Excel-DNA
I still can't resolve this issue.  Anyone have any ideas?

Govert van Drimmelen

unread,
May 14, 2022, 3:32:03 PMMay 14
to Excel-DNA
Hi Rich,

I tried the code and it works for me.
I wonder if you have some global 'Imports' that makes a confusion between different 'Application' types. So there is both 'Microsoft.Office.Interop.Excel.Application' and 'System.Windows.Forms.Application'.
You might just need to fully qualify that type.

-Govert

Rich Russell

unread,
May 14, 2022, 4:59:22 PMMay 14
to Excel-DNA
Thanks Govert - I'll give that a try.

Rich Russell

unread,
May 15, 2022, 7:44:33 AMMay 15
to Excel-DNA
Success!  Thanks again Govert!  
Reply all
Reply to author
Forward
0 new messages