VB.net close Custom Task Pane

Hi

I am using the code below to load a UserControl called "TpSqlEdit" as a Custom Task Pane at the bottom of the screen in Excel. What code would I use to make the custom task pane go away (become invisible) using a button click event on the task pane itself:

Public Class TpSQLEdit

    Private Sub buttonCloseTp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonCloseTp.Click
         '######### CODE NEEDED HERE ############
    End Sub
End Class

Public Class ThisAddIn


    Private _tpSqlEdit As TpSQLEdit
    Public TpSqlEditCustomTaskPane As Microsoft.Office.Tools.CustomTaskPane


    Private Sub ThisAddIn_Startup() Handles Me.Startup
        'Fire the Custom TaskPane
        AddTpSqlEdit()
    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub

    'Create the Custom TaskPane and Dock Bottom
    'You must Add your Control here
    Private Sub AddTpSqlEdit()
        _tpSqlEdit = New TpSqlEdit()
        TpSqlEditCustomTaskPane = CustomTaskPanes.Add(_tpSqlEdit, "SQL Editor")
        TpSqlEditCustomTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionBottom
        'Show TaskPane
        TpSqlEditCustomTaskPane.Visible = True
    End Sub


End Class
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
Try

 CustomTaskPanes.Remove(_tpSqlEdit)
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi

I get that both  "CustomTaskPanes"  and "_tpSqlEdit" are not declared
0
 
CodeCruiserCommented:
Where are you calling that code? _tpSqlEdit  is class level so should be accessible.
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
This is behind TpSQLEdit.vb file (UserControl), and I call the code at the line marked with 'XXXXX

Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.Excel


Public Class TpSQLEdit

    Private Sub buttonGetData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonGetData.Click
        Call PopulateFromSql()
    End Sub

    Private Sub PopulateFromSql()
        Try
            'Dim strCN As String = "server=196.220.43.247,1444;uid=murbro73;pwd=chestnut3;database=test"
            ' DataTable Construction with Adapter and Connection
            Dim conn = New SqlConnection(textBoxCS.Text)
            Dim strSql = richTextBoxSQLEdit.Text
            conn.Open()
            Dim da = New SqlDataAdapter(strSql, conn)
            Dim dt = New System.Data.DataTable()
            da.Fill(dt)

            ' Define the active Worksheet
            Dim sht = TryCast(Globals.ThisAddIn.Application.ActiveSheet, Worksheet)

            Dim rowCount = 0
            progressBarGetData.Minimum = 1
            progressBarGetData.Maximum = dt.Rows.Count

            ' Loop thrue the Datatable and add it to Excel
            For Each dr As DataRow In dt.Rows
                rowCount += 1
                For i As Integer = 1 To dt.Columns.Count
                    ' Add the header the first time through
                    If rowCount = 2 Then
                        ' Add the Columns using the foreach i++ to get the cell references
                        If sht IsNot Nothing Then
                            sht.Cells(1, i) = dt.Columns(i - 1).ColumnName
                        End If
                    End If
                    ' Increment value in the Progress Bar
                    progressBarGetData.Value = rowCount
                    ' Add the Columns using the foreach i++ to get the cell references
                    If sht IsNot Nothing Then
                        sht.Cells(rowCount, i) = dr(i - 1).ToString()
                    End If
                    ' Refresh the Progress Bar
                    progressBarGetData.Refresh()
                Next
            Next
        Catch ex As Exception
            Throw New Exception(ex.ToString())
        End Try

    End Sub

    Private Sub buttonCloseTp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonCloseTp.Click
        CustomTaskPanes.Remove(_tpSqlEdit) 'XXXXXXXX
    End Sub

    Private Sub label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles label1.Click

    End Sub

    Public Sub Load_DataGridView()


        Dim ColumnLetters As String
        Dim Ltr As Object
        'Dim Target As Object
        'Dim cboTemp As Object
        Dim I As Integer

        For I = 1 To 10

            'Ltr = Split(Range("B5").Address(True, False), "$")
            'Col = Ltr(0)

            Ltr = Split(Globals.ThisAddIn.Application.Range(Globals.ThisAddIn.Application.Cells(1, I), Globals.ThisAddIn.Application.Cells(1, I)).Address(True, False), "$")
            ColumnLetters = Ltr(0)

            'Add ComboBoxes
            'Target = Globals.ThisAddIn.Application.Range(Globals.ThisAddIn.Application.Cells(1, I), Globals.ThisAddIn.Application.Cells(1, I))

            'cboTemp = Globals.ThisAddIn.Application.ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1")

            'cboTemp.Name = ColumnLetters


            'With cboTemp

            '.Visible = True
            '.Left = Target.Left
            '.Top = Target.Top
            '.Width = Target.Width + 3
            '.Height = Target.Height + 5

            'End With



        Next I

    End Sub


End Class
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.