How To Execute An Excel VBA Macro From Python

Coding Is Fun
Coding Is Fun
38.5 هزار بار بازدید - 3 سال پیش - 👉 Explore All My Excel
👉 Explore All My Excel Solutions: https://pythonandvba.com/solutions

𝗗𝗘𝗦𝗖𝗥𝗜𝗣𝗧𝗜𝗢𝗡
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
This video will show how to execute an Excel VBA macro from Python using the xlwings library.

✅ 𝗦𝗢𝗨𝗥𝗖𝗘 𝗖𝗢𝗗𝗘:
import xlwings as xw

-- OPEN WORKBOOK
wb = xw.Book("Macro_Example.xlsm")

--- EXAMPLE 1
macro1 = wb.macro("Module1.SimpleMsgBox")
macro1()

--- EXAMPLE 2
macro2 = wb.macro("Module1.MsgBoxWithInput")
macro2("Ahoy")

--- SAVE & CLOSE WORKBOOK
wb.save()
if len(wb.app.books) == 1:
   wb.app.quit()
else:
   wb.close()


𝗧𝗢𝗢𝗟𝗦 𝗔𝗡𝗗 𝗥𝗘𝗦𝗢𝗨𝗥𝗖𝗘𝗦
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
🆓【𝗙𝗥𝗘𝗘】Excel Add-in (𝗠𝘆𝗧𝗼𝗼𝗹𝗕𝗲𝗹𝘁): https://pythonandvba.com/mytoolbelt
📊 Dashboard Excel Add-In (𝗚𝗿𝗮𝗳𝗹𝘆): https://pythonandvba.com/grafly
🎨 Cartoon Charts Excel Add-In (𝗖𝘂𝘁𝗲𝗣𝗹𝗼𝘁𝘀): https://pythonandvba.com/cuteplots
🤪 Fun Emoji Excel Add-In (𝗘𝗺𝗼𝗷𝗶𝗳𝘆): https://pythonandvba.com/emojify
📑 Excel Templates: https://pythonandvba.com/go/excel-tem...
🎓 My Courses: https://pythonandvba.com/go/courses
📚 Books, Tools, and More: https://pythonandvba.com/resources


𝗖𝗢𝗡𝗡𝗘𝗖𝗧 𝗪𝗜𝗧𝗛 𝗠𝗘
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
🔗 LinkedIn: LinkedIn: sven-bosau
📸 Instagram: Instagram: codingisfun_official
💻 GitHub: https://github.com/Sven-Bo
💬 Discord: https://pythonandvba.com/discord
📬 Contact: https://pythonandvba.com/contact


☕ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲?
If you want to support this channel, you can buy me a coffee here: https://pythonandvba.com/coffee-donation
3 سال پیش در تاریخ 1400/05/30 منتشر شده است.
38,595 بـار بازدید شده
... بیشتر