title: Permission error for running Python on the back of VBA
body: <p>I am trying to create a simple excel file with a button to populate the cells from an excel file. The issue I am having is that if I have my excel file open, python can't open the excel due to permission error (since the file is already open). I know a simple way is to create variables in VBA and let python do all the calculations and then pass it back to VBA. And then VBA will populate the cells. That's not what I am trying to do. I have seen people online to be able to keep excel open while run python and populate simultaneously. What am I missing? Is there some way to give permission to the python when opening from the VBA?</p>
  <p>Integrating the Python to VBA seems to be fairly simple. I made a module in VBA using this code:</p>
  <pre><code>Sub RunPythonScript()
  
  Dim objShell As Object
  Dim PythonExePath, PythonScriptPath As String
      Set objShell = VBA.CreateObject(&quot;Wscript.Shell&quot;)
      
      PythonExePath = &quot;&quot;&quot;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe&quot;&quot;&quot;
      PythonScriptPath = &quot;E:\My Documents\Finance\Economy\excel2.py&quot;
      
      objShell.Run PythonExePath &amp; PythonScriptPath
      
  End Sub 
  </code></pre>
  <p>And for python:</p>
  <pre><code>from openpyxl import load_workbook
  wb = load_workbook('Python_Button.xlsm')
  ws = wb[&quot;Sheet1&quot;]
  
  for i in range (1,21):
      currentCell = &quot;A&quot; + str(i)
      ws[currentCell] = i
  wb.save('Python_Button.xlsm')
  wb.close()
  </code></pre>