下面的代码引发“运行时错误5”:无效的过程调用或参数

如果有人build议为什么在添加ModelRelationship.Add的Excelmacros中抛出错误,那将会非常好

'Add the relation Public Sub AddRelation(ParentTableName As String, ParentColumnName As String, ChildTableName As String, ChildColumnName As String) Dim relations As ModelRelationships Set relations = ActiveWorkbook.model.ModelRelationships Dim tables As ModelTables Set tables = ActiveWorkbook.model.ModelTables Dim ptIndex As Integer ptIndex = TableIndex(ParentTableName, tables) Dim pfIndex As Integer pfIndex = ColumnIndex(ParentColumnName, tables(ptIndex)) Dim ftIndex As Integer ftIndex = TableIndex(ChildTableName, tables) Dim ffIndex As Integer ffIndex = ColumnIndex(ChildColumnName, tables(ftIndex)) **relations.Add _ ForeignKeyColumn:= _ tables(ftIndex).ModelTableColumns(ffIndex), _ PrimaryKeyColumn:= _ tables(ptIndex).ModelTableColumns(pfIndex)** End Sub