Form Kontrolüne Makro Atama
Contents
[
Hide
]
Aspose.Cells for Python via .NET, bir Forma Kontrolü gibi bir makro kodu atamanıza izin verir. Çalışma kitabı içindeki bir Forma Kontrolüne yeni bir Makro Kodu atamak için Shape.macro_name özelliğini kullanın.
Aşağıdaki örnek kod, yeni bir çalışma kitabı oluşturur, Form Düğmesine bir Makro Kodu atar ve çıktıyı XLSM biçiminde kaydeder. Çıktı XLSM dosyasını Microsoft Excel’de açtığınızda aşağıdaki makro kodunu göreceksiniz.
Sub ShowMessage()
MsgBox "Welcome to Aspose!"
End Sub
Python’da Forma Kontrolüne Makro Atama
Çıktı XLSM dosyasını Makro Kodu ile oluşturmak için örnek kod burada.
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) |