如果有人建议在excel宏中添加ModelRelationship.Add时为什么会抛出错误
那会很棒'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