Author Topic: Excel functions with optional arguments  (Read 1487 times)


  • Newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
Excel functions with optional arguments
« on: February 13, 2014, 06:14:40 PM »
With Excel VBA we can define UDFs with optional args, and we can do the same in python, but I can't find a way to create one with the xl_func decorator.  Of course, I'm suggesting that an optional argument is something with a default value.  Is there something undocumented, or is it just not possible yet.



  • Administrator
  • Hero Member
  • *****
  • Posts: 661
  • Karma: 15
    • View Profile
Re: Excel functions with optional arguments
« Reply #1 on: February 13, 2014, 06:24:56 PM »

in some sense all arguments are optional in excel. If you miss arguments when calling the function Excel will call the underlying function implementation with its own default values, which depend on the argument type. There is no way when registering a function to say what the default value should be. This is a limitation of the Excel XLL SDK.

If you use the 'var' type a missing value will be passed as None, which you can check for and substitute in your default. This isn't as convenient as python's keyword argument defaults but it should be workable.

Best regards,