The project I am working on will create a .CSV file for the user to look at if needed.
If my script tries to open the .CSV file while the user has the file open in excel, my script will initiate os.system("taskkill /im EXCEL.EXE")
.
This closes Excel program so that my script can write to the file since the logging is more important than the file being open.
My issue and where I need help is this:
If the user has changed ANYTHING in the excel file while it is opened, when the taskkill
command is sent, excel prompts "would you like to save?".
So my script continues to initiate the taskill
command over and over until either Excel, or my script crashes.
QUESTIONS:
1.How can I let my script know when this prompt occurs?
2.How can I tell Excel "No Do Not Save" using python script, if this prompt occurs?
This is the function I am referring to:
def unlockDoor(x, y):
userDictionary = shelve.open(UserDict)
print('Welcome,',userDictionary[x])
print('Door Unlocked')
while True:
try:
with open(EntryLog, "a") as log:
log.write("{0},{1},{2},{3}\n".format(time.strftime("%Y-%m-%d %H:%M:%S"), x, userDictionary[x],y))
userDictionary.close()
break
except:
os.system("taskkill /im EXCEL.EXE")