Microsoft VBScript 运行时错误 缺少对象: 'mdl' (0x800A01A8)
在第29行 已经加粗注释了
Dim mdl ' the current model
set mdl = ActiveModel
If(mdl Is Nothing) Then
MsgBox "There is no Active Model"
End If
Dim HaveExcel
Dim RQ
RQ = vbYes 'MsgBox("Is Excel Installed on your machine ?", vbYesNo +
Dim xlapp 'Excel对象
Dim xlbook 'Excel工作薄
Dim xlsheets 'Excel工作表
Dim sheet 'Excel工作表
If RQ= vbYes Then
HaveExcel = True
set xlapp = createobject( "Excel.Application" )
xlapp.workbooks.open "C:\Users\Administrator\Desktop\data.xlsx"
set xlbook = xlapp.workbooks (1)
set xlsheets=xlbook.worksheets
Else
HaveExcel = False
End If
Function ImportTable(sheet,mdl) '传入模型和工作表导入到模型中
Dim rowIndex '行号
Dim table '表
Dim tableName'保存表名,作为返回值
Dim col '列
with sheet
set table=mdl.Tables.createNew '在模型中创建一张表
tableName=.cells(2,2).value '获取表英文名
table.Name=.cells(1,2).Value '设置模型表的中文名称
table.code= tableName'设置表英文名
table.comment=.cells( 1,2 ).value '设置表的注释
end with
For rowIndex = 4 To 1000 Step 1 '循环设置表中的列
with sheet
'判断是否已经读取完所有列,如果读取完退出
If .cells (rowIndex,1).value = "" Then
Exit For
End If
set col = table.columns.createNew'模型中创建列
col.Name = .cells( rowIndex,1)'设置列的中文名
col.code = .cells( rowIndex,2)'设置列的英文名
col.DataType = .cells(rowIndex,4)'设置列的数据类型
col.comment = .cells ( rowIndex,3)'设置列的COMMENT
End with
Next
End Function
MsgBox xlsheets.count
Dim Count
Count=0
For Each sheet in xlsheets
ImportTable sheet,mdl
Next