Solved

VB.net close Custom Task Pane

Posted on 2012-03-20
5
800 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:murbro
  • 3
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
Try

 CustomTaskPanes.Remove(_tpSqlEdit)
0
 

Author Comment

by:murbro
Comment Utility
Hi

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

Expert Comment

by:CodeCruiser
Comment Utility
Where are you calling that code? _tpSqlEdit  is class level so should be accessible.
0
 

Author Comment

by:murbro
Comment Utility
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
 

Author Closing Comment

by:murbro
Comment Utility
thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now