1

I'm writing an Excel add-in in VB.NET using the Interop Library. I write code with Option Strict On which dis-allows late-binding but I can normally get around this by explicitly casting the type. However, there is what appears to be an undeclared property/method on a chart (DisplayValueNotAvailableAsBlank) which works fine if I allow late-binding, but I'm unable to cast it properly because it isn't recognised by the intellisense.

I can wrap it up in a separate sub as shown in the code, so I can just have a single module with late-binding, but it seems a bit unsatisfactory to me. This must also be a problem in C#.


    Sub HideNAValues(myChart As Chart, valIn As Boolean)

        myChart.DisplayValueNotAvailableAsBlank = valIn

    End Sub


   public void HideNAValues(Chart myChart, bool valIn)
     {
       myChart.DisplayValueNotAvailableAsBlank = valIn;
     }

In VB I can set and use this property and it works correctly provided that I allow late-binding. If I disallow late-binding or use C# then I can't. How can I overcome this?

  • In C#, do `dynamic dynChart = myChart;` and then try to work with that. – Peter B May 20 '19 at 12:43
  • 1
    In VB.NET, there is no `dynamic` and `Option Strict Off` is more or less the counterpart, per [this](https://stackoverflow.com/q/2889974/4137916) (which also has various workarounds for late binding with `Strict` off. – Jeroen Mostert May 20 '19 at 12:46

0 Answers0