我创建了一个接收三个参数的函数:
当我编译时,我收到一个编译错误说明:
编译错误: 预期:=
我的电话是:
Sub C_Button_ImportBOM_Click()
Dim strFilePathName As String
Dim strFileLine As String
Dim v As Variant
Dim RowIndex As Long
Dim mySheet As Worksheet
ActiveSheet.Name = "Import"
mySheet = Worksheets("Import")
strFilePathName = ImportFilePicker
v = QuickRead(strFilePathName)
For RowIndex = 0 To UBound(v)
PopulateNewLine (v(RowIndex), mySheet, RowIndex)
Next
End Sub
函数声明是:
Function PopulateNewLine(SourceString As String, ImportSheet As Worksheet, CurrentRow As Long)
我尝试了很多事情但无济于事。最初只使用声明和使用的第一个参数,这个工作正常。
任何想法都非常感激。
Excel 2010 VBA
答案 0 :(得分:1)
您正在将函数称为子例程,即您没有从中返回值并将其赋值给变量,就像您通常使用函数一样。这意味着你需要在没有围绕参数的括号的情况下调用它:
PopulateNewLine v(RowIndex), mySheet, RowIndex
如果你真的没有从它那里归还任何东西,为了清楚起见你应该把它变成一个Sub:
Sub PopulateNewLine(SourceString As String, ImportSheet As Worksheet, CurrentRow As Long)
... your code here
End Sub
另外请注意,您应该对mySheet引用进行限定,并且正如我在评论中提到的那样,使用Set
。它应该看起来像:
Set mySheet = ActiveWorkbook.Worksheets("Import")
替换上面的ActiveWorkbook
导入的任何工作簿。