0

Is there any built in method or any other way to translate a python numpy array/list to COM SAFEARRAY?

There is a similar method in R: R Matrix to COMSAFEARRAY

Quite weirdly I have not found anything in python.

I want to use it in order to pass an array into a VBA function which I call from python.

Thank you

1 Answers1

1

xlwings takes care of this:

import xlwings as xw
import numpy as np

book = xw.Book()
book.sheets[0]['A1'].value = np.array([[1, 2], [3, 4]])
Felix Zumstein
  • 6,737
  • 1
  • 30
  • 62
  • Well yes in that case it’s ok. BUT, when I am trying to pass a list in a macro which has a VBA function which accept something as variant, I get an error saying TypeError: Objects for SAFEARRAYS must be sequences (of sequences) or a buffer object. Any workaround? – wanna_be_quant Dec 08 '20 at 09:11
  • In addition Felix, how can optional parameters in a VBA function be treated when calling it from python? I have not seen anything in the documentation – wanna_be_quant Dec 08 '20 at 09:24
  • I think it makes more sense to ask these questions in GitHub issues, if you don't mind. – Felix Zumstein Dec 08 '20 at 12:50