Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python to run excel macro

from win32com.client import Dispatch


def run_excel_macro():
    try:
        excel = Dispatch("Excel.Application")
        excel.Visible = True
        workbook = excel.Workbooks.Open(
            r"D:DocumentsBook1.xlsm")

        workbook.Application.Run("Module1.Example")
        workbook.SaveAs(r"D:DocumentsBook5.xlsm")
        excel.Quit()
    except IOError:
        print("Error")


if __name__ == "__main__":
    run_excel_macro()
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #run #excel #macro
ADD COMMENT
Topic
Name
6+6 =