VSTO & .NET & Excel

October 25, 2009

The New Package; Windows 7, VS.NET 2010 and Office 2010

Filed under: .NET & Excel, COM Add-ins, VSTO & Excel — Dennis M Wallentin @ 1:55 am

To create a workable structure I have always grouped individual new versions of Windows, VS.NET, VSTO and Office together. The present groups I work with are:

  • Windows XP, VS.NET 2005, VSTO 2005 SE, SharePoint 2003 and Office XP/Office 2003
  • Windows Vista, VS.NET 2008, VSTO 3.0, SharePoint 2007 and Office 2007
  • Windows 7, VS.NET 2010, VSTO 4.0 SharePoint 2010 and Office 2010

The list also reflects my different configuration guest systems on the VMware platform. I have recently replaced Windows Vista 64-bit with Windows 7 64-bit as my host system. The grouping can also be said to represent the optimal situation where we develop solutions with the .NET/VSTO version included targeting the Office version(s) included. At least that is my experience.

While Windows 7 RTM has been released VS.NET 2010 and Office 2010 are still in the beta stage as of this writing. Beta 2 of VS.NET 2010 came out this week while Office 2010 officially still is in beta 1. To complete the picture; Exchange 2010 RTM seems to be around the corner and SharePoint 2010 will soon be in the beta stage.

I have been taking part of the Office beta testing but only for Excel. I have no intention to make any walkthrough about what is new in Excel 2010. It already exist a great number of blogposts and sites that cover all the news in detail like Microsoft Excel Team Blog and Microsoft Office 2010 Engineering

As for the operating system the real successor to Windows XP is Windows 7 and not Windows Vista . The later will probably get the same position as Windows ME already have in all history books. With Windows 7 we get a modern operating system, with more secured network functions, a flexible User Acess Control (UAC) together with a new folder system and improved tools for music and video. Despite all the new “whistle and bells” it is as fast as Windows XP for all kind of operations, including file operations. 

The news in VS.NET 2010 is nearly all about SharePoint developing. VB.NET has also been improved and among other things working with Collection and Array Initializers have been improved and added. As for the other languages I have not been testing anyone of them. The major news in the Beta 2 version is that VSTO 4.0 now is included. At present I’m evaluating VSTO 4.0 so I will get back to it in an upcoming blogpost.

Office 2010 includes news for all the softwares in the suite and will also be better integrated with SharePoint than any previously version. With Office 2010 we also get a new Web based Office suite. My major concern is Excel 2010 desktop version so the other tools as well as the Web based suite are less important to me. Unlike Office 2007 we now can customize the Ribbon UI via a built-in UI and Outlook 2010 has now also fully implemented the Ribbon UI. As a developer I was rather negative surprised when it turned out that we did not get any more events methods in code to control the Ribbon UI with. The Office Button has, together with its content, been revised and improved. The new programming language did not made it to this version so it looks like we will have to wait for Office 15.0.

For Excel 2010 the major news is that we finally have got a 64-bit version of it – Please see the discussion about the 64-bit version here: Excel 2010 – Now With More Bits!. With the 64-bit version it is possible to work with really large datasets which can consume more memory then 4 GB. The future will tell us to which degree we need to develop separated solutions for the 64-bit and 32-bit version of Excel.

Microsoft continues to develop the management of large datasets including data analyse, especially data visualization in Excel. Among the news in Excel 2010 are SparkLines and an improved Pivot Table tool including Slicers. The later allows us to filter data in real-time and when the data is updated so are the Slicers updated. The integration between Excel and SQL Server will in general be handle by the Business Intelligence tool (BI) Microsoft SQL Server PowerPivot for Excel which is an add-in to Excel 2010.

I must honestly say that Microsoft has managed to put the pieces together with the new versions and my overall impression of all the software are positive. Next year will be the year when Microsoft will have a complete updated versions of all the server platforms as well as the other software suites. That is impressive!

Kind regards,
Dennis

October 17, 2009

Install and Activate Add-ins in Excel with SamLogic’s Visual Installer

Filed under: COM Add-ins, Installation Tools, Tools, VSTO & Excel — Dennis M Wallentin @ 1:10 am

In the first part of this post I discuss how to work with the collection of add-ins as well as individual add-ins in Excel when using VB.NET/VSTO. In the second part the installation tool Visual Installer will be discussed in terms of installing and activating native add-ins in Excel.

Part I – Add-ins
When working with add-ins we need to separate native add-ins and unmanaged/managed COM and VSTO add-ins from each other. In this example I use a VSTO add-in to call the collections and add-ins.

If we want to load, i.e. activate, an add-in during a session the code below shows how to do it:

Private Const m_sXLDATA As String = "Data.xlsm"
Private Const m_sXLAREPORT As String = "C:\Data\Report.xlam"
Private Const m_sXLAREPORT_DISPLAYNAME As String = "Report"

Private Sub Application_WorkbookOpen( _
                ByVal Wb As Microsoft.Office.Interop.Excel.Workbook) _
                Handles Application.WorkbookOpen

        Try
            If Wb.Name.ToString() = m_sXLDATA Then
                With Globals.ThisAddIn.Application
                    .AddIns.Add(Filename:=m_sXLAREPORT)
                    .AddIns(m_sXLAREPORT_DISPLAYNAME).Installed = True
                End With
            End If
        Catch ex As Exception
            MsgBox(ex.Message.ToString())
        End Try

End Sub

Private Sub Application_WorkbookBeforeClose( _
                ByVal Wb As Microsoft.Office.Interop.Excel.Workbook, _
                ByRef Cancel As Boolean) _
                Handles Application.WorkbookBeforeClose

        Dim xlAddin As Excel.AddIn = Nothing

        Try
            If Wb.Name.ToString = m_sXLDATA Then
                For Each xlAddin In _
                Globals.ThisAddIn.Application.AddIns
                    If xlAddin.FullName = m_sXLAREPORT Then
                        xlAddin.Installed = False
                        Exit For
                    End If
                Next
            End If
        Catch ex As Exception
            MsgBox(ex.Message.ToString())
        End Try

End Sub

As we can see it does not differ from how we do it in VBA. If we want to load a COM add-in or a VSTO add-in it can be done in the following way:

Private m_xlCOMAddins As Office.COMAddIns
Private m_xlCOMData As Office.COMAddIn

Private Const m_sXLDATA As String = "Data.xlsm"
Private Const m_sXLDATAANALYZE As String = "SQL Tester NET 2010.AddinModule"

Private Sub Application_WorkbookOpen( _
                ByVal Wb As Microsoft.Office.Interop.Excel.Workbook) _
                Handles Application.WorkbookOpen

        m_xlCOMAddins = Globals.ThisAddIn.Application.COMAddIns
        m_xlCOMData = m_xlCOMAddins.Item(m_sXLDATAANALYZE)

        Try
            If Wb.Name.ToString() = m_sXLDATA Then
                If m_xlCOMData.Connect = False Then _
                m_xlCOMData.Connect = True
            End If
        Catch ex As Exception
            MsgBox(ex.Message.ToString())
        End Try

End Sub

Private Sub Application_WorkbookBeforeClose( _
                ByVal Wb As Microsoft.Office.Interop.Excel.Workbook, _
                ByRef Cancel As Boolean) _
                Handles Application.WorkbookBeforeClose

        m_xlCOMAddins = Globals.ThisAddIn.Application.COMAddIns
        m_xlCOMData = m_xlCOMAddins.Item(m_sXLDATAANALYZE)

        Try
            If Wb.Name.ToString = m_sXLDATA Then
                If m_xlCOMData.Connect Then _
                m_xlCOMData.Connect = False
            End If
        Catch ex As Exception
            MsgBox(ex.Message.ToString())
        End Try

End Sub

Again, it does not differ from how it’s done in VBA.

Part 2 SamLogic’s Visual Installer
In the past I have made comments on various blogs and at Q&A forums about an installation tool that can help us with the installation and with the activation of native Excel add-ins in a smooth way. I finally decided to make a blogpost about this superb tool. I have been using it for years and so far I have not seen any other tool that makes it so easy to set up the installation instructions. The software I talk about is Visual Installer 2008 from the Swedish company SamLogic.

At present Visual Installer 2008 is available in Swedish but it can create set up packages in English. Anyway, whenever I need to distribute native add-ins and related files I use it. It also works great with .NET packages including managed COM add-ins.

For the demonstration purpose here I use an add-in with name Report.xlam. To set it up in Visual Installer it only requires one line (!) as the below screen shot show:

Visual Installer 2008

The command XLADDIN trigger Visual Installer to add the required entry in the Windows Registry. After the installation the entry exist in the Registry as the following screen shot shows (OPEN5):

Windows Registry Entry

When we uninstall the add-in the entry in the Windows Registry is silently removed. All in all, I find it to be an excellent companion.

Although I do not agree I know some VBA developers that have several Excel versions installed side by side. When using Visual Installer the add-ins are installed once but are registered for all available Excel versions on configurations with multiply versions installed.

The next version, i.e. Visual Installer 2010, will also support the 64-bits Windows platform as well as Windows 7.

Kind regards,
Dennis

Create a free website or blog at WordPress.com.