title: Python: Open Excel Workbook using Win32 COM Api
body: <p>I'm using the following code to open and display a workbook within Excel:</p>
  
  <pre><code>import win32com.client as win32
  excel = win32.gencache.EnsureDispatch('Excel.Application')
  wb = excel.Workbooks.Open('my_sheet.xlsm')
  ws = wb.Worksheets('blaaaa') 
  excel.Visible = True
  </code></pre>
  
  <p>When the File 'my_sheet.xlsm' is already opened, Excel asks me whether I want to re-open it without saving. </p>
  
  <p>How could I check in advance whether the workbook is already opened up and in case it is, just bring it to the front?</p>
  
  <p><strong>EDIT</strong>: Found out by now:</p>
  
  <pre><code>if excel.Workbooks.Count &gt; 0:
      for i in range(1, excel.Workbooks.Count+1):
          if excel.Workbooks.Item(i).Name is 'my_sheet.xlsm':
              wb = excel.Workbooks.Item(i)
              break
  </code></pre>
  
  <p><strong>And one more question</strong>: My worksheet contains some headers where I enabled some filtering. So when the filters are set, and when I open the Workbook from Python, it sometimes asks me to enter a unique name to save the filter. Why is that? This is the dialogue:</p>
  
  <p><a href="https://i.stack.imgur.com/j3D6B.png" rel="noreferrer"><img src="https://i.stack.imgur.com/j3D6B.png" alt="enter image description here"></a></p>
  
  <p><strong>EDIT</strong> Ok here it says (in german language) that the latter problem is a known bug in 2007 and 2010 files: <a href="https://social.msdn.microsoft.com/Forums/de-DE/3dce9f06-2262-4e22-a8ff-5c0d83166e73/excel-api-interne-namen" rel="noreferrer">https://social.msdn.microsoft.com/Forums/de-DE/3dce9f06-2262-4e22-a8ff-5c0d83166e73/excel-api-interne-namen</a> and it seems to exist if you open Excel-Files programmatically. Don't know whether there is a workaround.</p>