Excel supports native dialogs, through the SDK DIALOG() interface. XLL+ contains several classes which make it easy to use native dialogs:
To implement your own native dialog, you should create a class descended from CXlDialog, and initialise it with its component controls.
This walkthrough demonstrates how to create and use a native Excel dialog.
To create the project using Visual Studio 6
To create the project using Visual Studio .NET or Visual Studio 2005
For more details about creating projects, see Creating an add-in project in the XLL+ User Guide.
Adding the dialog class
#include "DlgDemo.h" #include <xldialog.h>
class CMyDialog : public CXlDialog {
public:
// Controls
CXlControlStatic lblIntro;
CXlControlRefEdit edtRef;
CXlControlOK btnOK;
CXlControlCancel btnCancel;
public:
// Constructor - contains all initialisation
CMyDialog()
: CXlDialog("My Dialog", 300, 65)
{
// Set label text
lblIntro.SetText("Please select a range of cells");
// Set OK button position
btnOK.SetPos(220, 11);
// Set cell reference to current cell
CXlOper xloRef;
if (xloRef.GetActiveCell())
edtRef.SetRef(xloRef);
// Add all controls to the dialog
Add(4, &lblIntro, &edtRef, &btnOK, &btnCancel);
// Set the initial focus
SetFocus(edtRef);
}
};
Using the dialog class
// Function: ShowMyDialog
// Purpose: Shows a user-defined dialog
//{{XLP_SRC(ShowMyDialog)
// NOTE - the FunctionWizard will add and remove mapping code here.
// DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN2(ShowMyDialog, "A", "ShowMyDialog", "",
"User Defined", "Shows a user-defined dialog", "", "", 2)
extern "C" __declspec( dllexport )
BOOL ShowMyDialog()
{
//}}XLP_SRC
// Show the dialog
CMyDialog dlg;
if (!dlg.Show())
{
// User cancelled
return FALSE;
}
// Get the cell reference from the dialog
CXlOper xloRef;
if (dlg.edtRef.GetRef(xloRef))
{
// Paste a value into the dialog's selected cell(s)
xloRef.SetValue("abcd");
}
return TRUE;
}
To test the add-in
