@@ -139,10 +139,20 @@ Sub ImportPythonUDFs(control As IRibbonControl)
139139
140140 f.Write ftype + " " + fname + "("
141141 first = True
142+ vararg = ""
143+ nArgs = Py.Len(Py.GetItem(xlfunc, "args" ))
142144 For Each arg In Py.GetItem(xlfunc, "args" )
143145 If Not Py.Bool(Py.GetItem(arg, "vba" )) Then
146+ argname = Py.Str(Py.GetItem(arg, "name" ))
144147 If Not first Then f.Write ", "
145- f.Write Py.Str(Py.GetItem(arg, "name" ))
148+ If Py.Bool(Py.GetItem(arg, "vararg" )) Then
149+ f.Write "ParamArray "
150+ vararg = argname
151+ End If
152+ f.Write argname
153+ If Py.Bool(Py.GetItem(arg, "vararg" )) Then
154+ f.Write "()"
155+ End If
146156 first = False
147157 End If
148158 Next arg
@@ -151,9 +161,17 @@ Sub ImportPythonUDFs(control As IRibbonControl)
151161 f.WriteLine sTab + "If TypeOf Application.Caller Is Range Then On Error GoTo failed"
152162 End If
153163
164+ If vararg <> "" Then
165+ f.WriteLine sTab + "ReDim argsArray(1 to UBound(" + vararg + ") - LBound(" + vararg + ") + " + CStr(nArgs) + ")"
166+ End If
167+ j = 1
154168 For Each arg In Py.GetItem(xlfunc, "args" )
155169 If Not Py.Bool(Py.GetItem(arg, "vba" )) Then
156170 argname = Py.Str(Py.GetItem(arg, "name" ))
171+ If Py.Bool(Py.GetItem(arg, "vararg" )) Then
172+ f.WriteLine sTab + "For k = lbound(" + vararg + ") to ubound(" + vararg + ")"
173+ argname = vararg + "(k)"
174+ End If
157175 If Not Py.Var(Py.GetItem(arg, "range" )) Then
158176 f.WriteLine sTab + "If TypeOf " + argname + " Is Range Then " + argname + " = " + argname + ".Value2"
159177 End If
@@ -176,21 +194,34 @@ Sub ImportPythonUDFs(control As IRibbonControl)
176194 End If
177195 f.WriteLine sTab + "End If"
178196 End If
197+ If Py.Bool(Py.GetItem(arg, "vararg" )) Then
198+ f.WriteLine sTab + "argsArray(" + CStr(j) + " + k - LBound(" + vararg + ")) = " + argname
199+ f.WriteLine sTab + "Next k"
200+ Else
201+ If vararg <> "" Then
202+ f.WriteLine sTab + "argsArray(" + CStr(j) + ") = " + argname
203+ j = j + 1
204+ End If
205+ End If
179206 End If
180207 Next arg
181208
182- f.Write sTab + "Set args = Py.Tuple("
183- first = True
184- For Each arg In Py.GetItem(xlfunc, "args" )
185- If Not first Then f.Write ", "
186- If Not Py.Bool(Py.GetItem(arg, "vba" )) Then
187- f.Write Py.Str(Py.GetItem(arg, "name" ))
188- Else
189- f.Write Py.Str(Py.GetItem(arg, "vba" ))
190- End If
191- first = False
192- Next arg
193- f.WriteLine ")"
209+ If vararg <> "" Then
210+ f.WriteLine sTab + "Set args = Py.TupleFromArray(argsArray)"
211+ Else
212+ f.Write sTab + "Set args = Py.Tuple("
213+ first = True
214+ For Each arg In Py.GetItem(xlfunc, "args" )
215+ If Not first Then f.Write ", "
216+ If Not Py.Bool(Py.GetItem(arg, "vba" )) Then
217+ f.Write Py.Str(Py.GetItem(arg, "name" ))
218+ Else
219+ f.Write Py.Str(Py.GetItem(arg, "vba" ))
220+ End If
221+ first = False
222+ Next arg
223+ f.WriteLine ")"
224+ End If
194225
195226 If Py.Bool(Py.GetItem(xlfunc, "xlwings" )) Then
196227 f.WriteLine sTab + "Py.SetAttr Py.GetAttr(Py.Module(""xlwings""), ""xlplatform""), ""xl_app_latest"", Application"
@@ -243,18 +274,18 @@ not_present:
243274 For Each arg In xlargs
244275 If Not Py.Bool(Py.GetItem(arg, "vba" )) Then nArgs = nArgs + 1
245276 Next arg
246- If nArgs > 0 And Application.Version >= 14 Then
277+ If nArgs > 0 And Val( Application.Version) >= 14 Then
247278 ReDim argdocs(1 To WorksheetFunction.Max(1 , nArgs)) As String
248279 nArgs = 0
249280 For Each arg In xlargs
250281 If Not Py.Bool(Py.GetItem(arg, "vba" )) Then
251282 nArgs = nArgs + 1
252- argdocs(nArgs) = Py.Str(Py.GetItem(arg, "doc" ))
283+ argdocs(nArgs) = Left$( Py.Str(Py.GetItem(arg, "doc" )), 255 )
253284 End If
254285 Next arg
255- XLPMacroOptions2010 "'" + wb.name + "'!" + fname, fdoc, argdocs
286+ XLPMacroOptions2010 "'" + wb.name + "'!" + fname, Left$( fdoc, 255 ) , argdocs
256287 Else
257- Application.MacroOptions "'" + wb.name + "'!" + fname, Description:=fdoc
288+ Application.MacroOptions "'" + wb.name + "'!" + fname, Description:=Left$( fdoc, 255 )
258289 End If
259290 End If
260291 Next svar
0 commit comments