I am working on a directory code, where if the file exists in the path specified, it would run a macro on excel. For my else, I want to make it so if the path is not there, the file will be saved to the F
drive from the master copy from the I drive
and then run the code. How can I do that?
import os
import os.path
PATH='F:\Ten Year Load Forecasts 2017-2026.xlsm'
Master_Copy='I:\Ten Year Load Forecasts 2017-2026.xlsm'
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
print "File exists and is readable"
xlApp = win32com.client.DispatchEx('Excel.Application') # Running Excel
xlsPath = os.path.expanduser('F:\Ten Year Load Forecats\Ten Year Load Forecasts 2017-2026.xlsm)# Reading xlsm file
wb = xlApp.Workbooks.Open(Filename=xlsPath) # Opening file
xlApp.Run('csvfile3')# Running macro---- csvfile3 is the macro name. It is under the "csv" module in the VBA editor
wb.Save()
xlApp.Quit()
else:
"Save Master_Copy to Path"
"Repeat Function From above with running macro"