Assegna Macro a Controllo Modulo
Contents
[
Hide
]
Aspose.Cells ti consente di assegnare un codice Macro a un Controllo Modulo come un Pulsante. Si prega di utilizzare la proprietà Shape.MarcoName per assegnare un nuovo codice Macro a un Controllo Modulo all’interno del workbook.
Il codice di esempio seguente crea un nuovo workbook, assegna un codice Macro a un pulsante di modulo e salva l’output nel formato XLSM. Una volta aperto il file XLSM di output in Microsoft Excel, vedrai il codice Macro seguente.
Sub ShowMessage()
MsgBox "Welcome to Aspose!"
End Sub
Assegna Macro a Controllo Modulo in C#
Qui c’è il codice di esempio per generare il file XLSM di output con il codice Macro.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
if (!System.IO.Directory.Exists(dataDir)) | |
{ | |
System.IO.Directory.CreateDirectory(dataDir); | |
} | |
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(); | |
Aspose.Cells.Worksheet sheet = workbook.Worksheets[0]; | |
int moduleIdx = workbook.VbaProject.Modules.Add(sheet); | |
Aspose.Cells.Vba.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 = Aspose.Cells.Drawing.PlacementType.FreeFloating; | |
button.Font.Name = "Tahoma"; | |
button.Font.IsBold = true; | |
button.Font.Color = System.Drawing.Color.Blue; | |
button.Text = "Aspose"; | |
button.MacroName = sheet.Name + ".ShowMessage"; | |
dataDir = dataDir + "Output.out.xlsm"; | |
workbook.Save(dataDir); |