VBA多参数函数调用语法错误 [英] VBA multi-parameter function call Syntax Error

查看:115
本文介绍了VBA多参数函数调用语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Excel VBA(2007)中调用一个函数,并且在调用中收到语法错误.我有一个称为ImportSets的数据结构数组,其中包含工作表和字符串,并且正在尝试将该数组中的项目成员传递给一个名为Import的函数.

I'm trying to call a function in Excel VBA (2007), and am recieving a syntax error on the call. I have an array of data structures called ImportSets, which contains worksheets and strings, and am trying to pass members of items in that array to a function, called Import.

调用代码如下:

The calling code looks like this:

For n = 1 To 7  
    Debug.Print ("Destsheet: " & ImportSets(n).DestSheet.name)  
    Debug.Print ("Sourcesheet: " & ImportSets(n).SourceSheet.name)  
    Debug.Print ("Sourcecolumn: " & ImportSets(n).SourceColumn)  
    Import(CostAnalysisWorksheet.Sheets("Reimbursements"), ImportSets(n).DestSheet, ImportSets(n).SourceSheet, ImportSets(n).SourceColumn)  
Next n  

所有Debug.Print语句均返回有意义且正确的字符串,并检查是否存在偿还",则返回true.方法调用在一行上.这是ImportSet对象代码:

All of the Debug.Print statements return meaningful and correct strings, and check for the existence of "Reimbursements" returns true. The method call is on one line. Here is the ImportSet object code:

Public Type ImportSet
    DestSheet As Worksheet
    SourceSheet As Worksheet
    SourceColumn As String
    ...other code...
End Type

函数主体如下:

The function body looks like this:

Function Import(ByRef ReimbursementSheet As Worksheet, ByRef DestSheet As Worksheet, ByRef ImportSheet As Worksheet, ByRef ImportSheetPriceColumn As String) As String  
    ....code here .....  
End Function

在函数调用中(第一个代码段中)出现红色突出显示的语法错误.我可能想念一些愚蠢的东西.什么事?

I am getting a red-highlighted syntax error on the function call (in the first snippet). I am probably missing something stupid. What is it?

推荐答案

我没有在Excel 2007中使用VBA,但是较旧的版本仅在将返回值分配给变量时才允许在函数调用参数前后加上方括号.试试这个:

I haven't used VBA in Excel 2007 but older versions only allow you to put brackets around function call parameters if you're assigning the return value to a variable. Try this:

Import CostAnalysisWorksheet.Sheets("Reimbursements"), ImportSets(n).DestSheet, ImportSets(n).SourceSheet, ImportSets(n).SourceColumn

这篇关于VBA多参数函数调用语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆