We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Assign macro to form button controls in .NET using C#

In the following code snippet, a macro and a button is created, respectively. Is it possible to assign macro to a form button, so that when the button is clicked when the excel file is opened, the macro will be called ?

The image shows the "Assign macro" function in Excel 2013.

PS:
It seems that this request is related to "CELLSNET-13561" as mentioned in the post below:

Workbook workbook = new Workbook();

Worksheet sheet = workbook.Worksheets[0];

int moduleIdx = workbook.VbaProject.Modules.Add(sheet);

VbaModule module = workbook.VbaProject.Modules[moduleIdx];

module.Codes =

"Sub ShowMessage()" + "\r\n" +

" MsgBox \"Welcome to Aspose!\"" + "\r\n" +

"End Sub";

Aspose.Cells.Drawing.Button button = sheet.Shapes.AddButton(2, 0, 2, 0, 28, 80);

button.Placement = PlacementType.FreeFloating;

button.Font.Name = "Tahoma";

button.Font.IsBold = true;

button.Font.Color = Color.Blue;

button.Text = "Aspose";

// How to assign the macro to the button

workbook.Save("testbutton.xlsm");

Hi,

Thanks for your posting and considering Aspose.Cells.

We are afraid, this feature is not available however we have logged this issue in our database for investigation. We will look into it and implement this feature if possible. Once there is some fix or other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43880 - Assign macro to form controls

Hi,

This is to inform you that we have fixed your issue and supported the feature. We will soon provide the fix here after performing QA and including other enhancements and fixes.

Once the fix is available for public use, we will let you know immediately.

Keep in touch.

Thank you.
Amjad Sahi:
Hi,

This is to inform you that we have fixed your issue and supported the feature. We will soon provide the fix here after performing QA and including other enhancements and fixes.

Once the fix is available for public use, we will let you know immediately.

Keep in touch.

Thank you.

Really great work ! Looking forward to the new version !

Hi,

Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET (Latest Version) and let us know your feedback.

Please try this fix with the following code:

C#
Workbook workbook = new Workbook();

Worksheet sheet = workbook.Worksheets[0];

int moduleIdx = workbook.VbaProject.Modules.Add(sheet);

VbaModule module = workbook.VbaProject.Modules[moduleIdx];

module.Codes =
“Sub ShowMessage()” + “\r\n” +
" MsgBox “Welcome to Aspose!”" + “\r\n” +
“End Sub”;

Aspose.Cells.Drawing.Button button = sheet.Shapes.AddButton(2, 0, 2, 0, 28, 80);
button.Placement = PlacementType.FreeFloating;
button.Font.Name = “Tahoma”;
button.Font.IsBold = true;
button.Font.Color = Color.Blue;
button.Text = “Aspose”;

button.MacroName = “Sheet1.ShowMessage”;

The issues you have found earlier (filed as CELLSNET-43880) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.