Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic examples only work with a modification of xlpython.xlam #12

Closed
alex-ifx opened this issue Sep 2, 2014 · 12 comments
Closed

basic examples only work with a modification of xlpython.xlam #12

alex-ifx opened this issue Sep 2, 2014 · 12 comments

Comments

@alex-ifx
Copy link

alex-ifx commented Sep 2, 2014

Hi!

I have just started with xlpython today and I was unable to run this example:

from xlpython import *

@xlfunc
def DoubleSum(x, y):
    '''Returns twice the sum of the two arguments'''
    return 2 * (x + y)

Excel was complaining about the following line:

Sub XLPMacroOptions2010(macroName As String, desc, argdescs() As String)
    Application.MacroOptions macroName, Description:=desc, ArgumentDescriptions:=argdescs
End Sub

I have changed it to:

Sub XLPMacroOptions2010(macroName As String, desc, argdescs() As String)
    Application.MacroOptions macroName, Description:=desc
End Sub

... and now it works.

What is causing this and how can I avoid this situation?

I use Windows 7 and Excel 2007.

Thank you!

Best regards,
Alex

@ericremoreynolds
Copy link
Owner

Hi Alex,
The line

Application.MacroOptions macroName, Description:=desc, ArgumentDescriptions:=argdescs

is indeed invalid on Excel 2007, but the VBA code should be written in such a way that it does not enter into that function on versions < 2010, so I do not understand why it is raising this error. (I myself use 2007 and it doesn't complain.)

Could you do me a favour and tell me what the output of typing

?Application.Version

is on your PC?

Thanks, regards,

Eric

@alex-ifx
Copy link
Author

alex-ifx commented Sep 2, 2014

It is 12.0

@ericremoreynolds
Copy link
Owner

It not clear to me why the line

If nArgs > 0 And Application.Version >= 14 Then

is not stopping VBA from entering into the function. Could you send me a screenshot please?

@alex-ifx
Copy link
Author

alex-ifx commented Sep 2, 2014

err

translation:
error while compiling:
named argument not found

@ericremoreynolds
Copy link
Owner

I get that error when I try to compile the VBA project:

image

But there is no need to compile it. I do not get the error when I run the functions from the add-in buttons:

image

Do you confirm that you are getting the error even when running the functions from the add-in buttons?

Thanks for your patience, regards,

Eric.

@alex-ifx
Copy link
Author

alex-ifx commented Sep 2, 2014

could it be a language setting problem?

In my localized version of Excel (german version), 12.0 is usually written as 12,0

Furthermore the version number seems to be a string anyway, so I am not sure (VBA newbie) whether you can compare it to an integer.

@ericremoreynolds
Copy link
Owner

Excellent insight regarding the comma! Yes that is very probably the cause of the problem.

It can be fixed by replacing the line

If nArgs > 0 And Application.Version >= 14 Then

with

If nArgs > 0 And Val(Application.Version) >= 14 Then

Actually you can do that string vs. int comparison in VBA, only apparently it is not clever enough to consider the globalization settings.

If you confirm that it works with this modification then I will include it in the next release.

@alex-ifx
Copy link
Author

alex-ifx commented Sep 2, 2014

I think I now have a broken setup and not because of the change you have recommended. I have tried to reproduce my workaround from the first post with a fresh copy of the .xlam file but that does not work (#VALUE!).
Your workaround avoids the initial error but also leads to #VALUE!
Something or more precisely the command line completion seems to work though, because it suggests the function that I have defined.

I have no clue what I did to make this fail so please give me some time to fix my setup before I can give you a final confirmation.

@ericremoreynolds
Copy link
Owner

Ok, well if you need any more help please just ask!
Regards,
Eric.

@alex-ifx
Copy link
Author

alex-ifx commented Sep 2, 2014

Argh! This whole comma/ point/ semicolon thing is a nightmare.

I was following your example that says I have to write =DoubleSum(1,2)

What I actually do need to write instead is =DoubleSum(1;2) to make it work.

I would like to express my gratitude for your timely replies and coming up with a fix so quickly. I really appreciate it. Thank you very much!

Cheers,
Alex

@ericremoreynolds
Copy link
Owner

Yes it is very irritating how the Excel syntax works differently in different locales. Often the function names change too, for example if the language is Italian the SUM function becomes SOMMA.

I find that for anything but the most basic uses of Excel it is best just to change the system language to US or UK English.

@ericremoreynolds
Copy link
Owner

However thanks very much for finding that bug with the version number!

Definitely going into the next release.

ericremoreynolds added a commit that referenced this issue Sep 29, 2014
+ Added variable arguments length UDFs
+ VBA7/64-bit `PtrSafe` bug fix in `xlpython.bas`
+ Bug fixes #12 and #14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants