VB.net close Custom Task Pane

Posted on 2012-03-20
Medium Priority
Last Modified: 2012-06-27

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
    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
Question by:Murray Brown
  • 3
  • 2
LVL 83

Accepted Solution

CodeCruiser earned 2000 total points
ID: 37741404


Author Comment

by:Murray Brown
ID: 37741466

I get that both  "CustomTaskPanes"  and "_tpSqlEdit" are not declared
LVL 83

Expert Comment

ID: 37743982
Where are you calling that code? _tpSqlEdit  is class level so should be accessible.

Author Comment

by:Murray Brown
ID: 37744265
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()
            'Dim strCN As String = "server=,1444;uid=murbro73;pwd=chestnut3;database=test"
            ' DataTable Construction with Adapter and Connection
            Dim conn = New SqlConnection(textBoxCS.Text)
            Dim strSql = richTextBoxSQLEdit.Text
            Dim da = New SqlDataAdapter(strSql, conn)
            Dim dt = New System.Data.DataTable()

            ' 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
        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

Author Closing Comment

by:Murray Brown
ID: 37763056

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

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.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Watch the video to know the simple way to remove or recover or reset lost or forgotten passwords of Outlook PST file. With Kernel Outlook Password Recovery tool such operation is very easy to perform. It is a freeware with limitation to use with 500…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question