title: closing an excel file using python if file is already open
body: <p>Hi I am new to python scripting, I wrote a code for SAP automation but at last excel file open so I want to close that file.</p>
  
  <p>I need a help regarding code to check if specific excel file is already open, if open than closing the same using python.</p>
  
  <p>Thanks for help in advance.</p>
  
  <p>I am using below code:</p>
  
  <pre><code>        with open('C:\\Users\\Xyz\\AppData\\Local\\Temp\\export.XLSX', 'r') as f:
          f.close()
  </code></pre>
  
  <p>Also if someone can hep me converting VBA function in python and can tell me how to call the same.</p>
  
  <pre><code>Function WKopen(wb As String) As Boolean
  On Error Resume Next
  WKopen= Len(Workbooks(wb).Name)
  End Function
  
  Sub BK_Close()
  On Error Resume Next
  If WkOpen("Export_Download.XLSX") Then
  Workbooks("Export_Download.xlsx").Close savechanges:=False
  Else
  End If
  End Sub
  </code></pre>