Custom Task Pane in VB: System.ArgumentNullException:

56 views
Skip to first unread message

Manh Nguyen Van

unread,
Aug 24, 2019, 10:54:49 PM8/24/19
to Excel-DNA
Hi All
I am new in ExcelDna, not moving VBA to VB.Net with ExcelDna
but when I tried to make CTP as the Sample the get  the error. So where am I wrong?
System.ArgumentNullException: as picture below
Untitled.jpg
this is code revised for me
Imports ExcelDna.Integration.CustomUI
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.Windows.Forms
' Define the backing class for the Ribbon
' Would need to be marked with [ComVisible(true)] if in a project that is marked as [assembly:ComVisible(false)] which is the default for VS projects.
<ComVisible(True)> Public Class MyRibbon
    Inherits ExcelDna.Integration.CustomUI.ExcelRibbon
    Private ctp As CustomTaskPane
    Public Shared Sub ctp_VisibleStateChange(ctp As CustomTaskPane)
        MsgBox("Visibility changed to " & ctp.Visible)
    End Sub
    Public Shared Sub ctp_DockPositionStateChange(ctp As CustomTaskPane)
        Dim ctrl As MyUserControl
        ctrl = CType(ctp.ContentControl, MyUserControl)
        ctrl.TheLabel.Text = "Moved to " & ctp.DockPosition.ToString()
    End Sub
    Public Sub OnShowCTP(ByVal control As IRibbonControl)
        If ctp Is Nothing Then
            ctp = CustomTaskPaneFactory.CreateCustomTaskPane(Type.GetType("MyUserControl"), "My Super Custom Task Pane!")
            ctp.Visible = True
            ctp.DockPosition = MsoCTPDockPosition.msoCTPDockPositionLeft
            AddHandler ctp.DockPositionStateChange, AddressOf ctp_DockPositionStateChange
            AddHandler ctp.VisibleStateChange, AddressOf ctp_VisibleStateChange
        Else
            ctp.Visible = True
        End If
    End Sub
    Public Sub OnDeleteCTP(ByVal control As IRibbonControl)
        If Not ctp Is Nothing Then
            ctp.Delete()
            ctp = Nothing
        End If
    End Sub
End Class
' Define the UserControl to display on the CTP ///////////////////////////
' Would need to be marked with [ComVisible(true)] if in a project that is marked as [assembly:ComVisible(false)] which is the default for VS projects.
Public Class MyUserControl
    Inherits System.Windows.Forms.UserControl
    Public TheLabel As System.Windows.Forms.Label
    Public Sub New()
        TheLabel = New System.Windows.Forms.Label()
        TheLabel.Text = "Tinh Dao"
        TheLabel.Location = New System.Drawing.Point(20, 20)
        TheLabel.Size = New System.Drawing.Size(200, 60)
        Controls.Add(TheLabel)
    End Sub
End Class
and .dna file
<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="CTP Add-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2018/05/dnalibrary">
  <ExternalLibrary Path="CTP.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" />
  <!--
       The RuntimeVersion attribute above allows two settings:
       * RuntimeVersion="v4.0" - for .NET 4 and 4.5
       * RuntimeVersion="v2.0" - for .NET 2.0, 3.0 and 3.5
       You can have IntelliSense (autocomplete) and validation for this file.
       See https://github.com/Excel-DNA/ExcelDna/tree/master/Distribution/XmlSchemas/
       Additional referenced assemblies can be specified by adding 'Reference' tags.
       These libraries will not be examined and registered with Excel as add-in libraries,
       but will be packed into the -packed.xll file and loaded at runtime as needed.
       For example:
       <Reference Path="Another.Library.dll" Pack="true" />
       Excel-DNA also allows the XML for ribbon UI extensions to be specified in the .dna file.
       See the main Excel-DNA site at http://excel-dna.net for downloads of the full distribution.
  -->
  <CustomUI>
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
      <ribbon>
        <tabs>
          <tab id="tab1" label="Custom Task Pane cua Toi">
            <group id="SampleGroup" label="CTP Control">
              <button id="Button1" label="Show CTP" onAction="OnShowCTP" imageMso="AcceptInvitation" size="large" />
              <button id="Button2" label="Delete CTP" onAction="OnDeleteCTP" imageMso="DeclineInvitation" size="large" />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
  </CustomUI>
  <Reference Path="System.Windows.Forms.dll"/>
  <Reference Path="System.Drawing.dll"/>
</DnaLibrary>



Manh Nguyen Van

unread,
Aug 24, 2019, 11:18:53 PM8/24/19
to Excel-DNA
this time, I revise from GetType("MyUserControl") to GetType("CTP.MyUserControl") with CTP is the name of my project
and a new error showing below:

2.jpg



Vào 09:54:49 UTC+7 Chủ Nhật, ngày 25 tháng 8 năm 2019, Manh Nguyen Van đã viết:

Craig Crevola

unread,
Aug 25, 2019, 12:50:51 AM8/25/19
to exce...@googlegroups.com
Hi

The user control needs to have Com Visible set.

Thanks

Craig. 

--
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/662dd0dd-4464-4c00-a508-588eeb57571f%40googlegroups.com.

Manh Nguyen Van

unread,
Aug 25, 2019, 4:56:04 AM8/25/19
to Excel-DNA
Hi Craig
it worked
Thanks so much

Vào 11:50:51 UTC+7 Chủ Nhật, ngày 25 tháng 8 năm 2019, Craig đã viết:
To unsubscribe from this group and stop receiving emails from it, send an email to exce...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages