VB.NET adding .xla to Excel Menu

The code below runs in VB.Net. It adds an .XLA to the Excel Add-In Menu.  It is not working on Windows 64-Bit platform.

ERROR MESSAGE
Microsoft Visual Basic for Applications
Compile error:
The code in this project must be updated for use on 64-bit systems.  Please review and update Declare statements and then mark them with the PtrSafe attribute

Open in new window



  Friend Function LoadAsaExcelMenu() As Boolean
            Const messageTitle As String = "Add ASA Navigator button to Excel"

            Dim objExcel As Object = Nothing
            Dim blnExcelAlreadyLoaded As Boolean = False
            Try
                objExcel = GetObject(, "Excel.Application")
                blnExcelAlreadyLoaded = True
            Catch ex As Exception
                Try
                    objExcel = CreateObject("Excel.Application")
                Catch ex2 As Exception
                    MessageBox.Show("Could not get or create an instance of Excel.", messageTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    Return False
                End Try
            End Try
            If objExcel IsNot Nothing Then
                Try
                    Dim objWb As Object = objExcel.Workbooks.Add()
                    Try
                        Dim objAddin As Object = objExcel.AddIns.Add(Application.StartupPath & "\Excel Add-In\ASA Navigator.xla", True)
                        objAddin.Installed = True
                        objAddin = Nothing
                    Catch ex As Exception
                        LoadAsaExcelMenu = False
                        MessageBox.Show("Could not add ASA Navigator button to Excel (1).", messageTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    Finally
                        objWb.close(False)
                        objWb = Nothing
                    End Try

                    LoadASAExcelMenu = True
                Catch ex As Exception
                    LoadASAExcelMenu = False
                    MessageBox.Show("Could not add ASA Navigator button to Excel (2).", messageTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Finally
                    If blnExcelAlreadyLoaded = False Then
                        objExcel.Quit()
                    End If

                    Marshal.ReleaseComObject(objExcel)
                    GC.Collect()

                    objExcel = Nothing
                End Try
            End If
        End Function

        Friend Function UnloadAsaExcelMenu() As Boolean
            Const messageTitle As String = "Remove ASA Navigator button from Excel"

            Dim objExcel As Object = Nothing
            Dim blnExcelAlreadyLoaded As Boolean = False
            Try
                objExcel = GetObject(, "Excel.Application")
                blnExcelAlreadyLoaded = True
            Catch ex As Exception
                Try
                    objExcel = CreateObject("Excel.Application")
                Catch ex2 As Exception
                    MessageBox.Show("Could not get or create an instance of Excel.", messageTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    Return False
                End Try
            End Try
            If objExcel IsNot Nothing Then
                Try
                    Dim objWb As Object = objExcel.Workbooks.Add()
                    Try
                        objExcel.AddIns("ASA Navigator").Installed = False
                    Catch ex As Exception
                        UnloadAsaExcelMenu = False
                        MessageBox.Show("Could not remove ASA Navigator button from Excel (1).", messageTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    Finally
                        objWb.close(False)
                        objWb = Nothing
                    End Try

                    UnloadASAExcelMenu = True
                Catch ex As Exception
                    UnloadASAExcelMenu = False
                    MessageBox.Show("Could not remove ASA Navigator button from Excel (2).", messageTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Finally
                    If blnExcelAlreadyLoaded = False Then
                        objExcel.Quit()
                    End If

                    Marshal.ReleaseComObject(objExcel)
                    GC.Collect()

                    objExcel = Nothing
                End Try
            End If
        End Function

Open in new window

rrhandle8Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rrhandle8Author Commented:
Sorry, I got that wrong.  It works on Windows 64-bit but does not work with Excel 64-bit.
Jan Karel PieterseExcel and VBA ExpertCommented:
The problem is with an API declaration within the xla file. See http://jkp-ads.com/articles/apideclarations.asp for pointers.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.