当我尝试将Table对象传递给单独的函数时,我收到此ByRef argument type mismatch
错误。
发生错误的代码:
Dim doc As Word.Document
Set doc = ActiveDocument
For Each OuterTable In doc.Tables
For Each InnerTable In OuterTable.Tables
If InStr(InnerTable.Cell(1, 1).Range.Text, "SomeString") > 0 Then
currentCV.AddProject ExtractProjectInfo(InnerTable) ' <- Error here
End If
Next InnerTab
Next OuterTable
ExtractProjectInfo方法:
Function ExtractProjectInfo(projTable As Table) As Project
Dim proj As Project
Set proj = New Project
' Commented out code
Set ExtractProjectInfo = proj
End Function
传入任何其他对象都可以正常工作,它只是Table提供此错误。我假设我在这里错过了一些非常简单的东西?这种方法在某些方面确实起作用甚至更奇怪,我无法记住改变了与循环或功能相关的任何内容。
答案 0 :(得分:2)
您可以尝试将函数声明更改为 -
Function ExtractProjectInfo(ByVal projTable As Table) As Project
或添加此行 -
dim InnerTable as table
之前 -
For Each InnerTable In OuterTable.Tables