none
How to create a dialog for use by an Excel AddIn? RRS feed

  • Question

  • I know the basics of Excel AddIns, but have no idea how to design, implement and later display an internal dialog.

    The "Smart Quote Paste" function below is done, and it does not need any parameters. The function corresponding to the "New Project" button, however, needs to create a number of spreadsheets, provided by the user.

    TIA.

    Wednesday, January 21, 2015 10:57 PM

Answers

  • Hello Travis,

    For example:

    const string message =
            "Are you sure that you would like to close the form?";
        const string caption = "Form Closing";
        var result = MessageBox.Show(message, caption,
                                     MessageBoxButtons.YesNo,
                                     MessageBoxIcon.Question);
    
        // If the no button was pressed ... 
        if (result == DialogResult.No)
        {
            // cancel the closure of the form.
            e.Cancel = true;
        }
    

    If you want to customize it on your own, you can add a new Windows Form to the project and then add the required controls. After creating an instance of the form in the code you may show it using the Show or ShowDialog methods.

    • Marked as answer by Travis Banger Wednesday, January 28, 2015 5:58 PM
    Wednesday, January 28, 2015 5:34 PM

All replies

  • Here is how to ask for a number as input from the user:

    Sub GetSheetCount()
        Dim iShCount As Integer
        iShCount = Application.InputBox("How many sheets", Type:=1)
        MsgBox "You want " & iShCount & " new sheets...."

        'Use iShCount here in code    

    End Sub

    Thursday, January 22, 2015 1:42 PM
  • Hello Travis,

    You can use the System.Windows.Forms.MessageBox class. The Show method accepts different parameters where you can specify what buttons should be visible.

    Also you may consider creating your own dialog using the System.Windows.Forms.Form class. Treat your VSTO based add-in as a regular .Net application.

    Thursday, January 22, 2015 2:27 PM
  • Allow me to add the following:

    (1) My programming language is C#

    (2) I would like to draw the dialog, moving the buttons and text fields around, etc.

    Is that doable?

    TIA

    Saturday, January 24, 2015 1:41 AM
  • Hello Travis,

    For example:

    const string message =
            "Are you sure that you would like to close the form?";
        const string caption = "Form Closing";
        var result = MessageBox.Show(message, caption,
                                     MessageBoxButtons.YesNo,
                                     MessageBoxIcon.Question);
    
        // If the no button was pressed ... 
        if (result == DialogResult.No)
        {
            // cancel the closure of the form.
            e.Cancel = true;
        }
    

    If you want to customize it on your own, you can add a new Windows Form to the project and then add the required controls. After creating an instance of the form in the code you may show it using the Show or ShowDialog methods.

    • Marked as answer by Travis Banger Wednesday, January 28, 2015 5:58 PM
    Wednesday, January 28, 2015 5:34 PM