0

This question is for calling Python from Excel. In VBA you'd do your RunPython("import mymodule; mymodule.my_function()")

In Python you would have something like,

from xlwings import Workbook, Sheet, Range

    def my_function():
        wb = Workbook.caller() # Create reference to calling Excel file
        Range('A1:C3').clear_contents() # Clear some cells

My question is that this will work for your first instance of Excel. But in the event you have two instances open, and you're trying to run the code in the second instance, you will get a raised exception saying, "Can't establish connection! Make sure the calling workbook is the active one and is opened in the first instance of Excel."

So it seems like this is designed to work on only the first instance. Is there a way around this? Can you identify which instance you're in in the Python script? The user was hoping to run VBA macros that call Excel across multiple instances.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Matt
  • 1

1 Answers1

0

In principle, xlwings can deal with 2 instances. However, depending on your security settings, it might treat files downloaded from the internet or stored on a network drive as unsecure and "sandbox" them. These files are only accessible to xlwings if they run in the first instance. If this sounds like your issue, then lowering the security settings could potentially solve the issue. See also this answer here.

Community
  • 1
  • 1
Felix Zumstein
  • 6,737
  • 1
  • 30
  • 62