0

Generated a square.pyd file along with corresponding square.lib, square.exp, square.cpp using Cython from a square.pyx and setup.py file. How to use this square.pyd file with Excel VBA?

'''square.pyx
# -*- coding: utf-8 -*-
# distutils: language=c++

def square( unsigned int x):
    return (x * x)
'''

'''setup.py
# -*- coding: utf-8 -*-
from setuptools import setup
from Cython.Build import cythonize

setup(
      ext_modules = cythonize("square.pyx", annotate=True))
'''

'''build square.pyd
c:\myDir> python setup.py build_ext --inplace
'''

How do I use square.pyd (Windows DLL) in MS EXCEL as an Object Reference?

  • 1
    What do you mean by „use“? You need an (embedded) Python interpreter to be able to use ( I.e. import your extension). – ead Jul 16 '20 at 10:59
  • 1
    Here is an example how cython can be used to expose the functionality in a dll (which could be consumed from VBA): https://stackoverflow.com/q/18515275/5769463 – ead Jul 16 '20 at 11:14

1 Answers1

0

I am not entirely sure what you mean but hopefully this might help you. When you want to add extra libraries in MS Excel then you do that in VBA editor (ALT+F11). Then you find project (workbook) you want to work in and there is menu on top "Tools". There you select "References" and you browse and select your DLL. And then you should be able to call functions from mentioned library in VBA code.

R35P3K7
  • 96
  • 5