skip to Main Content

I created an "Excel VSTO document-level" project in Visual Studio. I have a pre designed "Action Pane" and a Tab Ribbon with a button in it to show my action pane.

My problem is my action pane keeps popping up (show) at least 1 time and quickly disappears before I do anything.

Here is my code so far in my ribbon:

Imports Microsoft.Office.Tools.Ribbon

Public Class Ribbon1

    Dim actionsPane1 As New ActionsPaneControl1()

    Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
        Globals.ThisWorkbook.ActionsPane.Clear()
        Globals.ThisWorkbook.ActionsPane.Controls.Add(actionsPane1)
        actionsPane1.Hide()
        Globals.ThisWorkbook.Application.DisplayDocumentActionTaskPane = False
    End Sub

    Dim boolAP1toggle As Boolean = True
    Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
        If boolAP1toggle = True Then
            Globals.ThisWorkbook.Application.DisplayDocumentActionTaskPane = True
            actionsPane1.Show()
            boolAP1toggle = False
        Else
            Globals.ThisWorkbook.Application.DisplayDocumentActionTaskPane = False
            actionsPane1.Hide()
            boolAP1toggle = True
        End If
    End Sub
End Class

2

Answers


  1. Chosen as BEST ANSWER

    I found my mistake:

    Globals.ThisWorkbook.ActionsPane.Controls.Add(actionsPane1)
    

    will inevitably show Actions Pane at the time when you try to add any form to it, so I needed to add it my Button1_Click event handler


  2. There is no need to show or hide methods of the pane class. Instead, you need to rely on the DisplayDocumentActionTaskPane property which is set to true to display the Document Actions task pane; set to false to hide the Document Actions task pane.

        Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
            If boolAP1toggle = True Then
                Globals.ThisWorkbook.Application.DisplayDocumentActionTaskPane = True
                boolAP1toggle = False
            Else
                Globals.ThisWorkbook.Application.DisplayDocumentActionTaskPane = False
                boolAP1toggle = True
            End If
        End Sub
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search