title: xlwings module.py call python from excel
body: <p>I keep receiving this error while trying to call the <a href="http://docs.xlwings.org/vba.html#call-python-with-runpython" rel="nofollow">module.py</a> file from excel</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;string&gt;", line 1, in &lt;module&gt;
    File "F:\ana\module.py", line 6, in rand_numbers
      wb = Workbook.caller()  # Creates a reference to the calling Excel file
  AttributeError: type object 'Workbook' has no attribute 'caller'
  </code></pre>
  
  <p>When I replace <code>wb = Workbook.caller()</code> with <code>wb = Workbook()</code> I receive this error</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;string&gt;", line 1, in &lt;module&gt;
    File "F:\ana\module.py", line 11, in rand_numbers
      rand_num = np.random.randn(n, n)
    File "mtrand.pyx", line 1341, in mtrand.RandomState.randn (numpy\random\mtrand\mtrand.c:11537)
    File "mtrand.pyx", line 1454, in mtrand.RandomState.standard_normal (numpy\random\mtrand\mtrand.c:11839)
    File "mtrand.pyx", line 142, in mtrand.cont0_array (numpy\random\mtrand\mtrand.c:1867)
  TypeError: an integer is required
  </code></pre>
  
  <p>Alternatively [scenario 2], I am able to call a python file from excel while using <a href="http://docs.xlwings.org/quickstart.html#interact-with-excel-from-python" rel="nofollow">this sample code</a></p>
  
  <pre><code>from xlwings import Workbook, Sheet, Range, Chart
  wb = Workbook()  # Creates a connection with a new workbook
  #wb = Workbook.caller()
  Range('A1').value = 'Foo 1'
  Range('A2').value = [['Foo 1', 'Foo 2', 'Foo 3'], [10.0, 20.0, 30.0]]
  Range('A13').table.value  # or: Range('A1:C2').value
  Sheet(1).name
  chart = Chart.add(source_data=Range('A2').table)
  </code></pre>
  
  <p>However the call in excel only works with <code>wb = Workbook()</code> and not <code>wb = Workbook.caller()</code></p>
  
  <p>I am aware of <a href="http://docs.xlwings.org/whatsnew.html?highlight=optimized#id4" rel="nofollow">this API documentation update</a> </p>
  
  <p><strong>module.py</strong></p>
  
  <pre><code>import numpy as np
  from xlwings import Workbook, Range
  
  def rand_numbers():
      """ produces std. normally distributed random numbers with shape (n,n)"""
      wb = Workbook.caller()  # Creates a reference to the calling Excel file
      n = Range('Sheet1', 'B1').value  # Write desired dimensions into Cell B1
      rand_num = np.random.randn(n, n)
      Range('Sheet1', 'C3').value = rand_num
  </code></pre>
  
  <p><strong>VBA code</strong></p>
  
  <pre><code>Sub MyMacro()
      RunPython ("import module; module.rand_numbers()")
  End Sub
  </code></pre>
  
  <p><strong>testing.py</strong> (test example code - scenario 2)</p>
  
  <pre><code>from xlwings import Workbook, Sheet, Range, Chart
  wb = Workbook()  # Creates a connection with a new workbook
  #wb = Workbook.caller()
  Range('A1').value = 'Foo 1'
  Range('A2').value = [['Foo 1', 'Foo 2', 'Foo 3'], [10.0, 20.0, 30.0]]
  Range('A13').table.value  # or: Range('A1:C2').value
  Sheet(1).name
  chart = Chart.add(source_data=Range('A2').table)
  </code></pre>
  
  <p><strong>VBA code</strong></p>
  
  <pre><code>Sub MyMacro()
      RunPython ("import testing") 
  End Sub
  </code></pre>