Using Iron Python I need to first determine if the excel file is already open and then if it is open, access it. if its not open then open it. problem: in my try statement when I try to open the workbook if its already open instead of failing the try it completes it instead and prompts the user to save / cancel the open file in excel. I want it to fail the try if the excel file is already open not prompt the user.
I use the Marshal Interopt lib to access the open file and that works well
UserExcelFile = os.path.join(userdirectory, 'podi.xlsx')
try:
workbook = excel.Workbooks.Open(UserExcelFile)
except:
print "Looks like it was already open"
return
workbook = excel.ActiveWorkbook
ws = excel.ActiveSheet
If the file is already open "workbook = excel.ActiveWorkbook" works perfect to edit the already open excel file.