Assegna Macro a Controllo Modulo
Contents
[
Hide
]
Aspose.Cells per Python via .NET permette di assegnare un Macro Code a un controllo modulo come un pulsante. Usa la proprietà Shape.macro_name per assegnare un nuovo Macro Code a un controllo modulo all’interno della cartella di lavoro.
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 Python
Qui c’è il codice di esempio per generare il file XLSM di output con il codice Macro.
This file contains hidden or 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
from aspose.cells import Workbook | |
from aspose.cells.drawing import PlacementType | |
from aspose.pydrawing import Color | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
if notpath.isdir(dataDir): | |
os.makedirs(dataDir) | |
workbook = Workbook() | |
sheet = workbook.worksheets[0] | |
moduleIdx = workbook.vba_project.modules.add(sheet) | |
module = workbook.vba_project.modules[moduleIdx] | |
module.codes = "Sub ShowMessage()" + "\r\n" + " MsgBox \"Welcome to Aspose!\"" + "\r\n" + "End Sub" | |
button = sheet.shapes.add_button(2, 0, 2, 0, 28, 80) | |
button.placement = PlacementType.FREE_FLOATING | |
button.font.name = "Tahoma" | |
button.font.is_bold = True | |
button.font.color = Color.blue | |
button.text = "Aspose" | |
button.macro_name = sheet.name + ".ShowMessage" | |
dataDir = dataDir + "Output.out.xlsm" | |
workbook.save(dataDir) |