Checking if cell is in edit mode

Posted by ToM on 16. Juli 2009 under VSTO Excel | Comments are off for this article

We observed a very strange behaviour while updating cells when the user is currently editing a cell.

After doing some research on the net it seems that the only solution to determine if the cell is in edit mode is a very strange hack :-)

Obviously, the Application object has a method called GoTo(Range) to navigate to some areas. Somehow throws this method a special exception if it’s in edit mode. So the strange solution so far is to call Application.GoTo(”###”) and see what kind of exception it throws :)

protected bool isInEditMode()
{
   try
   {
      this.Application.Goto("###", false);
   }
   catch (Exception ex)
   {
      if (ex.Message.StartsWith("Reference is not valid"))
        return false;
      else
        return true;
   }
   return false;
}

Orange Internet Everywhere

Posted by ToM on 13. Juli 2009 under Off-Topic | 7 Comments to Read

Nachdem ich mich nun wochenlang mit einem ICON 225 Adapter von Orange für Ihr Produkt “Internet Everywhere” rumgeärgert habe, dachte ich mir es ist mal an der Zeit einen kleinen Erfahrungsbericht zu schreiben.

Die ganze Geschichte hat so angefangen, dass ich längere Zeit zu einem Kunden musste um dort vor Ort zu arbeiten. Da die Security dort relativ strikt gehandhabt wird haben wir beschlossen, besagten USB Stick zu organisieren um mir zu ermöglichen, den Source Code via Memory Stick vom Rechner des Kunden auf mein Laptop zu kopieren und dort via Internet auf unserem Subversion Server einzuchecken.

Soweit so gut. Schnell stellte ich aber fest, dass es praktisch unmöglich ist, mit dem ICON 225 eine sinnvolle Verbindung zu erhalten. Sei dies mitten in Oerlikon oder im Herzen von Altstetten. Kurz gesagt egal wo ich war, es klappte nicht. Sollte es denn nach zehn Verbindungsversuchen zufällig mal klappen, liegt der Speed so ca. bei 800 B/s, für eine Weile…”eine Weile” deshalb, weil die Connection sogleich wieder abreisst, also wenn man Glück hat kann man eine SSH Connection zu einem Server aufbauen, die spätestens 30 Sekunden später wirder getrennt wird. Wenn man nur im Web surft muss man halt mit dem Abreissen der Connections leben.

Heute früh kam ich ins Büro und der Stick hat bereits nach drei Versuchen eine Connection. Juhu. Als ich dann ein Mail verschicken will schmeisst mich der Server raus weil er finden meine von Orange bezogene IP-Adresse sei auf diversen Spam-Blacklists. Also kein Mail heute.

Zwischenzeitlich brauche ich mindestens eine Stunde pro Tag um abverreckte SVN Checkins wieder zu reparieren, ja um überhaupt eine Connection zu bekommen. Eigentlich würde der ganze Task fünf Minuten dauern.

Schliesslich habe ich entnervt den Orange Support angerufen. Nachdem ich dann nach längerem hin und her tatsächlich mit einem echten Menschen sprechen konnte sagt mir dieser, ich sei ja selbst Schuld wenn ich mich auf so ein Produkt verlassen würde beim Arbeiten. Das sei nicht dafür gedacht und überhaupt ich könne froh sein wenn ich überhaupt eine Verbindung bekommen würde, das sei halt ein sehr neues Produkt und noch vor sechs Monaten wäre es praktisch unmöglich gewesen sich irgendwie einzuwählen.

Fazit: Orange Internet Everywhere scheint ein Produkt zu sein, dass stark beworben wird, in der Praxis aber absolut versagt hat, und damit meine ich komplett unbrauchbar. Was nützt mir so ein Teil wenn es doch nicht funktioniert ? Aber am schlimmsten ist ja schon das Orange genau weiss das es da enorme Probleme gibt, weiterhin fleissig Werbung macht und dem Kunden dann noch ins Gesicht sagt man sei ja selbst schuld wenn man ihre Produkte verwenden würde. LOOOOOL wie dämlich ist denn das ?

UDF Registration

Posted by ToM on 1. April 2009 under UDF | Read the First Comment

There are two ways to register an User Defined Formula in Excel:

  • Register it through the registry by adding the necessary keys, or
  • Load it programatically during runtime

Registering  during setup using the registry

To register the UDF during the setup process, you need to add a custom action to your setup project and add a key to

HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Options

The name of the key is OPEN[ID], while ID is an incrementing number. You therefore need to find an unused number and add the respective key. For example, if you have keys called OPEN1 and OPEN2, just call the new key OPEN3. If no OPEN[id] keys are defined at all, just call it OPEN. Set the added key’s value to “/A [ProgID of your add-in]“.

Register during runtime

This is my prefered solution because we also have a plugin loaded in Excel. This plugin registers the UDF dynamically at startup. To do so, we need to add two lines of code to the startup-method of the addin.

using Excel = Microsoft.Office.Interop.Excel;
.
.
.
// Add the UDF to the loaded plugins.
Excel.AddIn addin = Application.AddIns.Add("UDF-progID");
// Set installed state to true.
addin.Installed = true;

Display VSTO Error Messages

Posted by ToM on under Debugging Tips | Be the First to Comment

A very helpful trick is to set an user environment variable called VSTO_SUPPRESSDISPLAYALERTS to 0, this gives you more detailed information what’s going wrong during runtime.

Debugging Assembly Problems

Posted by ToM on under Debugging Tips | Be the First to Comment

If some of the components don’t load correctly and seem to do really nothing, you’ve a great chance that one or more of the required dependencies can’t be loaded.

Windows offers you a possibility to inspect what exactly happens when the assemblies are loaded (or not *g*)…The fusion log.

 

To enable the fusion log, create a directory to retrieve the log’s output, let’s say c:\fusionlog.

Now, several registry keys need to be set in order to enable the logging:

  • Set the path to your logfile directory in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\LogPath (in our example c:\fusionlog)
  • Set HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\LogFailures to 1
  • Optionally set HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\ForceLog to 1
  • Optionally set HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\LogResourceBinds to 1

There’s a tool called “Assembly Binding Log Viewer” available in the .NET Framework SDK, for more information look here.