简体   繁体   中英

Run VBA macro in workbook using Python xlsxwriter

I am a Python beginner so please have some patience.

I wonder is there a way that I can open and run a macro Excel code in a opened workbook before I close it ?

Here is a part of the code :

workbook = xlsxwriter.Workbook('Somedata.xlsx')
worksheet = workbook.add_worksheet()

# Write some numbers, with row/column notation.
# "save","identifier", "ISIN" "name" are just lists with data

worksheet.write_column(0, 1, save * number_of_rows)
worksheet.write_column(0, 2, identifier * number_of_rows)
worksheet.write_column(0, 3, ISIN)
worksheet.write_column(0, 4, name)


# Set coulmns width

worksheet.set_column('A:A', 15)
worksheet.set_column('B:C', 4)
worksheet.set_column('D:D', 13)
worksheet.set_column('E:E', 55)


workbook.close()

Thanks:)

This link explains it https://xlsxwriter.readthedocs.io/working_with_macros.html

You have to extract vbaProject.bin file and than add it to the XlsxWriter workbook using the add_vba_project() method:

workbook.add_vba_project('./vbaProject.bin')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM