1

I am trying to run a custom VBA function that will spill into multiple rows and columns.

When I generate a workbook using openpyxl with a function =MYFUNCTION() (or "=_xludf.MYFUNCTION()") opening it with excel replaces it with =@MYFUNCTION() not allowing it to properly go into multiple rows and columns

This code will generate the workbook fine, but when opening with Excel it seems to auto replace the function name. I need anyone who downloads this file to have it spill properly for them.

from openpyxl import load_workbook, Workbook

template_workbook = load_workbook("excel_file_with_vba.xlsm", keep_vba=True)

workbook = Workbook()
workbook.vba_archive = template_workbook.vba_archive
workbook.active = True

ws = workbook.worksheets[0]
ws.active = True
ws["A1"] = "=_xludf.MYFUNCTION()"
ws["A2"] = "=MYFUNCTION()"

workbook.save("test.xlsm")

Example output from code above still has =@MYFUNCTION()

I have looked at openpyxl: '@' is inserted to formula when saving to file which uses built in functions, and solutions do not work for this. And also tried the custom function prefix _xludf as mentioned in that thread with no change in results.

Cras
  • 11
  • 3

0 Answers0