|
请教高手
我现在有一个东西,它是根据所打开的工作表中的A列4到85的内容,即姓名,后台打开同一目录下的相应姓名对应的工作簿,取值写入当前工作表,为连续多次。但是运行中出错,提示“运行时错误'50290',方法’OPEN作用于对象'workbooks'时失败
过程如下:
Sub uniquedata()
Dim myApp As New Application, wkSht As Worksheet
'隐藏Excel
Dim cel As Range, res
Set d = CreateObject("scripting.dictionary")
myApp.Visible = False
'打开数据文件,并指定工作表对象
For Each cel In Range("a4:a85")
If cel <> " " Then
If Not d.exists(cel.Value) Then d.Add cel.Value, cel.Value
End If
Next
res = d.items
For i = 0 To d.Count - 1
Set wkSht = myApp.Workbooks.Open(ThisWorkbook.Path & "\b" & res(i) & ".xls").Sheets(2)
Cells(i + 4, 7) = res(i)
Cells(i + 4, 2) = wkSht.[b7]
Cells(i + 4, 3) = wkSht.[b8]
Cells(i + 4, 4) = wkSht.[e7]
Cells(i + 4, 5) = wkSht.[h8]
Cells(i + 4, 6) = wkSht.[d6]
'关闭Excel
myApp.Quit
Next i
Set wkSht = Nothing
Set myApp = Nothing
End Sub
Sub Silent_Open2()
Dim myObj As Object
' GetObject 返回工作表对象的引用
xm = [a2]
Set myObj = GetObject(ThisWorkbook.Path & "\b" & xm & ".xls")
[a3] = myObj.Sheets(2).Cells(6, 2)
'关闭工作簿
myObj.Close
Set myObj = Nothing
End Sub |
|