Skip to content

Instantly share code, notes, and snippets.

@drheinheimer
Created October 10, 2018 17:48
Show Gist options
  • Save drheinheimer/1fd4caeb54271481e5525c486737dbbe to your computer and use it in GitHub Desktop.
Save drheinheimer/1fd4caeb54271481e5525c486737dbbe to your computer and use it in GitHub Desktop.
# script to run the HHLSM model
import os, os.path
import win32com.client
# install win32com with "pip install pywin32"
HHLSM = "HHSM_2008_v3.1_PEIR_BD_VULNERABILITY.xlsm"
MACRO = "{}!HHSM_2008_v2.HHSM_2008_v2".format(HHLSM)
scenarios = [1,2,3]
if os.path.exists(HHLSM):
with win32com.client.Dispatch("Excel.Application") as xl:
xl.Workbooks.Open(os.path.abspath(HHLSM), ReadOnly=1) # not sure what the readonly arg value should be for updating values
for scenario in scenarios:
# add preprocessing here
xl.Application.Run(MACRO)
# add postprocessing here
xl.Application.Quit() # Comment this out if your excel script closes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment