Diego-MX
Diego-MX

Reputation: 2339

xlwings How to call macros from PERSONAL.XLS in Excel?

I refer to macros that include xlwings functionality. I do know how to call the macros, but I've had trouble integrating them with xlwings package. Allow me to explain.

I have included xlwings template code in the PERSONAL.XLSB, thus I'm able to call the package.

The first challenge was on adapting the PYTHONPATH to find the Python Scripts folder and read the corresponding module. I did this from within the PERSONAL.XLSB in Visual Basic.

-- PYTHONPATH = ThisWorkbook.Path
++ PYTHONPATH = "C:\Users\Diego-MX\Documents\Python Scripts"

After several tries to debug my macro, I came to presume that running the macro from a different spreadsheet doesn't capture the Workbook that I intend. That is xlwings.Workbook.caller() inside my macro will refer to PERSONAL.XLSB instead of my actual workbook.

Is there a way for me to pass the workbook argument from my spreadsheet, to PERSONAL.XLSB, and then to my xlwings macro?

I think this will solve my problem. Thanks.

Upvotes: 0

Views: 641

Answers (1)

Felix Zumstein
Felix Zumstein

Reputation: 7070

You'd have to refer to ActiveWorkbook instead of ThisWorkbook in the xlwings VBA module.

As a side note, there's an add-in planned (see here) which will probably also resolve your issue once available.

Upvotes: 1

Related Questions