Custom Task Pane Load from VBA

389 views
Skip to first unread message

Achilleas Stamos

unread,
Apr 30, 2021, 11:08:55 AM4/30/21
to Excel-DNA
Hello,

I have created a CTP per Govert's example code. If I add a button to the Ribbon to Show/Hide the CTP that works very well. However if I try to expose the ShowCTP() function via COM to vba and make the call to create/show the CTP through vba using the same exact function as the ribbon calls I get a System.NullReferenceException: 'Object reference not set to an instance of an Object'.

Has anyone encountered this issue before? Is there a workaround please?

Many Thanks,

Achilleas

Govert van Drimmelen

unread,
May 3, 2021, 10:06:16 AM5/3/21
to Excel-DNA
----------
Excel-DNA is now registered on GitHub Sponsors.
Please sign up as a sponsor to help fund future development.
----------

Hi Achilleas,

I wonder if you put the code inside a macro on the add-in side (so a public static void ShowTheTaskPane() ) method, and then called from VBA via Application.Run("ShowTheTaskPane").
This might put everything in the expected context, and avoid the error.

-Govert

Achilleas Stamos

unread,
May 3, 2021, 1:45:34 PM5/3/21
to Excel-DNA
Hi Govert,

many thanks for the prompt response.

I am already calling this via a macro like so:

Public Function ShowCTPVBA()

  Dim ctp as Test.CTP
  Set ctp = new Test.CTP

  ctp.ShowCTP()

End Function

where Test.CTP is a com class I have created that basically wraps the ShowCTP function of the CTPManager static class.

When I call the ctp.ShowCTP() line is where the error occurs in the CTPManager equivalent function.

You think if I wrap the ShowCTP function of the CTPManager in a UDF and call it using Application.Run() instead it would work better?

Achilleas

Govert van Drimmelen

unread,
May 3, 2021, 2:00:18 PM5/3/21
to exce...@googlegroups.com
Hi Achileas,

I mean that you should make a macro in the Excel-DNA add-in which would do the CTP stuff.
In C# it would be:

public static class MyMacros
{
    public static void ShowTheTaskPane()
    {
        // Here you call the Excel-DNA CTP stuff
    }
}

or in VB.NET your add-in code would be

Public Module MyMacros
    Public Sub ShowTheTaskPane()
        ' Here you call the Excel-DNA CTP stuff
    End Sub
End Module

Then the macro in VBA would look like this:

Sub ShowCTP()
    Application.Run "ShowTheTaskPane"
End Sub

I think that might work, but have not tried it myself.

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/a18fce38-8bf0-4243-b3b2-b33103fb3041n%40googlegroups.com.

Achilleas Stamos

unread,
May 3, 2021, 2:43:10 PM5/3/21
to Excel-DNA
Hi Govert,

that worked! 

Thanks a lot, 

Achilleas

Reply all
Reply to author
Forward
0 new messages