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 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, Tools, VSTO & Excel — Dennis 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

September 9, 2009

Goodbye Radio Buttons!

Filed under: .NET & Excel, COM Add-ins, UI Design, VSTO & Excel — Tags: — Dennis Wallentin @ 12:20 pm

For years I have been using the Radio Button control in many of my solutions (where it has been appropriated). When using the control it was usually together with the Group Box control. The following screen shot shows a common approach when using these two controls together and where users are supposed to select one of the three options. Typically one of the Radio Buttons is also pre-checked when the Windows Form is loaded.

RadioButtons

When designing the UI and consider to use Radio Buttons the question we should raise is; when is the number of items relevant to the end users? My answer is when the users are about to make a selection, not before and not after that decision point. After the decision has been made the selected item should be viewed. 

This lead to a new standpoint, at least to me, when designing UI; instead of a group of Radio Button controls we replace them with a Combo Box control as the following screen shot show:

Comboboxes

When the Windows Form is loaded we have the same option as with Radio Buttons; to have one (or more) item(s) selected or to have no no item pre-selected. When the users have made their decisions the selected item is showed in the control. Consequently,  the UI gets cleaner and the Windows form may even be down sized. Of course, the same discussion can be applied to the List Box control.

All in all, for all my future projects I will simple drop the Radion Button control and instead use the Combo Box control. Do You agree?

Kind regards,
Dennis

August 4, 2009

Connected to the network?

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

It has been a while since I last made a post here.  But I intend to get up to speed and publish on a more regular basis. Anyway, on the .NET platform and with VB.NET we can rather easy check if the computer we work on is connected to a network or not.

To know that information allows us:

  • To run methods that update workbooks with the latest data.
  • Run network located templates and individual workbooks.
  • Load network based add-ins.

Technically we will be using the My namespace to find out if the computer is connected or not.  More specifically we will use the  My.Computer namespace which provides methods to control the computer’s hardware and the system software.  Among other things, it allows us to work with the file system, clipboard, Windows Registry network printers, network connection and keyboard & mouse.

The following snippet code shows how we can use it to determine if the computer is connected to a network.

Network

 

Because the property isAvailable only indicates if there is a network available or not we need to make sure that there is a connection to the network we actually want to access. In order to do so we use the Ping function to insure that the wanted remote location is available.

Kind regards,
Dennis

January 4, 2009

.NET Framework Client Profile

Filed under: .NET & Excel, COM Add-ins, VSTO & Excel — Dennis Wallentin @ 1:57 pm

Recently there was a comment at Simon Murhpy’s blog about the file size of the .NET Framework Redistributable package and how it has grown for every new version:

  • .NET Framework 1.0 Redist: 19.7MB
  • .NET Framework 1.1 Redist: 23.1MB
  • .NET Framework 2.0 Redist: 22.4MB
  • .NET Framework 3.0 Redist: 50.3MB ( x86 )
  • .NET Framework 3.0 Redist: 90.1MB ( x64 )
  • .NET Framework 3.5 Redist: 197.0MB

Suppose we have a VSTO solution that was built on the latest version of the Framework and suppose also that the solution will be used on computers that, at present, do not have .NET Framework installed.

Based on the above information we would conclude that we need to deploy a nearly 200 MB large file. Are we mistaken or do we actually need to use this redistributable package?

Last year MSFT released a light weighted version, .NET Framework Client Profile, which is a subset of the full .NET Framework 3.5 SP-1 that target client applications.

For a great introduction to the .NET Framework Client Profile please see the following online resources:
.NET Framework Client Profile Deployment Guide
Introducing .NET Framework 3.5 SP1 Client Profile Preview

To download the package please use the following link:
http://www.microsoft.com/downloads/details.aspx?FamilyID=992CFFCB-F8CE-41D9-8BD6-31F3E216285C&displaylang=en

Kind regards,
Dennis

October 1, 2008

AddInSpy – The missing diagnostic tool!

Filed under: .NET & Excel, COM Add-ins, Tools, VSTO & Excel — Dennis Wallentin @ 7:59 pm

I thought that I should flag for the new diagnostic tool, AddInSpy, from MSFT. I have only started out to test it but I already like what I see. It can be a valuable source to detect present status for individual COM add-ins of all kind, i.e. managed, VSTO and unmanaged and provide a great number of values. 

The below screen shot shows a report that gives a detailed overview (it’s rather wide):

For more information please see:

AddInSpy – Diagnosing/Troubleshooting Office Add-ins

Kind regards,
Dennis

September 29, 2008

Everyone or Just Me?

Filed under: .NET & Excel, COM Add-ins, Tools, VSTO & Excel — Dennis Wallentin @ 12:28 am

When we install new software we usually are given the options to either install it to “Everyone” or “Just Me”. Under normal conditions this is not an issue but suppose that we only want to install the software to either the person (“Just Me”) who installs it or to everyone who will be using the computer?

In the first case, i.e. “Just Me”, it’s rather easy to solve it when using the Windows Installer. What we need to do is to set the property InstallAllUsers to False in the User Interface Editor

To change this setting we first select the Setup’s root node in the Solution Explorer, right click on it and from the menu select the command View > User Interface. In the editor’s window right click on the Installation Folder under the root node Install. Right click on it and from the menu select Properties Window. The following screen shot shows that the property’s value is now set to False:

 

Save and rebuild the Setup project. When running the Windows Installer the output of the above actions is that the software will only be installed to the person who installs it, i.e. ”Just Me”. The following screen shot shows how it looks when we have removed the “Everyone” option. In other words no visual options are available:

Of course, we need also tp update the settings accordingly in the Registry Editor so it reflect the visual design.

In the second case, install to everyone who use the computer, it’s more difficult to hide the option “Just Me”. At least, I have not yet find an easier way. The tool that comes to our rescue again is Orca (see UAC Compliant and The Orca Tool – A MSI Creator and Package Viewer). With Orca we can view the Setup package and also change the required settings.

I will not in detail describe the process as it is already documented by MSFT in their KB article 835460 – How to use the Orca database editor to remove the “Everyone” option and the “Just me” option from a Windows Installer package that you created by using Visual Studio .NET. Yes, that’s an impressive long title!

Kind regards,
Dennis

Learning LINQ

Filed under: .NET & Excel, COM Add-ins, SQL Server, Tools, VSTO & Excel — Dennis Wallentin @ 12:27 am

At present my time table does not permit me to explore new things so I have postponed delving into some areas to the next year.

However, in some cases I have made some research to get access to interesting sources and tools which I hope will help me out. LINQ is one area that is of high interest which may replace SQL within the foreseeable future. VS 2008 is the first development suite that includes LINQ.

The Book
I prefer books that target one specific area and the book LINQ in Action seems to fit in well. Actually, the book has its own site and it is also available as a PDF ebook. For more information please see LINQ in Action

The Tool
The tool LINQPAD seems to be very useful to learn and manage LINQ. It may also be more promising as it also is available for free. You can visit its homepage at the following URL: LINQPAD

The developer of this tool, Joseph Albahari, is also one of two authors of the book C# 3.0 in a Nutshell which is highly recommended if we want to learn C# together with another book, Programming C# 3.0.

Please feel free to comment available sources about LINQ as well as tools for learning how to use it.

Kind regards,
Dennis

July 31, 2008

VS 2008, COM Add-ins and launch conditions

Filed under: COM Add-ins — Dennis Wallentin @ 11:49 am

I can create COM add-ins based on the Shared Add-in template in VS 2008 and they all work well on my developing computer. However, I got an issue when I tried to deploy them on configurations where only .NET Framework 2.0 is installed.

In the New Project dialog we can select the targeting .NET Framework version, 2.0 or 3.0 or 3.5. Since I needed to get the COM add-ins to work with version 2.0 I selected that version and then continued to work with the add-ins.

To test that they work with the targeting .NET Framework version I deployed them on configurations with Windows XP SP-3 where only version 2.0 of .NET Framework was installed. I also tried to deploy them on a Windows Vista SP-1 configuration with .NET Framework 3.0 but I got the same outcome as with Windows XP.

The outcome was the following:

 

I was rather surprised by this message so I started to try to locate the source but first I couldn’t find any errors at all. Finally I took a closer look on the setup packages. There I found out that it exist a launch condition for every setup. It’s not possible to remove it so what we can do is to change its condition.

The following screen shot shows the default setting (despite the fact that .NET Framework 2.0 was explicit selected in the first place). In the left window we can see the launch condition and in the right window its present setting of the property Version:

This was easily to change as the following screen shot shows: 

I then compiled the setup packages again and deployed them. This time everything worked as expected on all platforms.

Hopefully this can be useful for other developers. I hope that the upcoming SP-1 for VS 2008 will include a fix for it.

Kind regards,
Dennis

July 26, 2008

VS 2008, Excel 2003 on Windows XP

Filed under: .NET & Excel, COM Add-ins — Dennis Wallentin @ 1:18 pm

Recently I faced a situation where I created a managed COM add-in, based on the Shared Add-in template in VS 2008, which didn’t work at all. The configuration I work with is:

  • Windows XP with SP-3 
  • Office 2003 with SP-3
  • VS 2008

I had no issue to create the managed COM add-in but when I debugged it didn’t work as expected. All the entries in the Windows registry seemed to be OK but it didn’t show up in the dialog for COM add-ins in Excel 2003. In addition, no error messages appeared so it was a ’silent’ error.

The solution to the issue is to install the KB908002 fix. However, if we run the exe package it first check to see if VS 2005 is installed or not. To overcome this process we need to decompile the exe package and then install the MSI package on its own.

I have made the MSI package available for download here.

Have anyone else experienced any issue with VS 2008?

Kind regards,
Dennis

Older Posts »

Blog at WordPress.com.