0

How could i assign a macro to a shape while being added using python pptx

Titleleft = Cm(25.37)  # 0.93" centers this overall set of shapes
Titleltop = Cm(14.56)
Titlelwidth = Cm(2.89)
Titlelheight = Cm(0.64 )

txBox = slide.shapes.add_textbox(Titleleft, Titleltop, Titlelwidth,Titlelheight)
tf = txBox.text_frame

p = txBox.text_frame.paragraphs[0]
p.alignment = PP_ALIGN.CENTER
run = p.add_run()
run.text = '16 / 17'

font = run.font
font.size = Pt(9)
font.bold = False
font.italic = None  # cause value to be inherited from theme

1 Answers1

0

Inserting VBA code (aka. macros) and the links for triggering them is not supported in python-pptx and is unlikely to be supported anytime soon given the binary format is not documented as far as I know.

scanny
  • 26,423
  • 5
  • 54
  • 80
  • How about inserting a call to a pre-existing macro? Use case would be to copy a presentation that already had macros into a new one, add the shape(s) and then add a reference to one of those macros. – Martin Packer Apr 22 '22 at 15:42