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()