|
你好,老师,能帮我看一下,问题出在哪了吗运行时错误 ...
运行时错误'424',要求对象,请各位老师帮我改一下
Sub 特殊()
For Each loWindow In Application.Windows
If LCase(loWindow.Caption) = "result.xls" Then
loWindow.Close (False)
End If
Next
If Dir("c:\result.xls") <> "" Then
Kill "c:\result.xls"
End If
ActiveWorkbook.Save
Set loConnection = CreateObject("ADODB.Connection")
Set loRecordset = CreateObject("ADODB.Recordset")
loConnection.Open "Driver={Microsoft Excel Driver (*.xls)}; " & _
"DBQ=" + ActiveWorkbook.FullName + ";" & _
"ReadOnly=True"
loRecordset.Open _
"select s1.*, IIF(IsNull(s2.入店时间),0,s2.入店时间),IIF(IsNull(s2.离店时间),0,s2.离店时间),IIF(IsNull(s2.金额),0,s2.金额),IIF(IsNull(s2.早餐费),0,s2.早餐费) " & _
"into [Excel 8.0;Database=c:\result.xls].[sheet1] from " & _
"[入住人员$] s1 left outer join [入住信息$] s2 on " & _
"(s1.单位 like '%" + s2.单位 + "%' and s1.时间 <= s2.离店时间 and s1.时间 >= s2.入店时间 ", loConnection
loConnection.Close
Workbooks.Open ("c:\result.xls")
ActiveWorkbook.ActiveSheet.UsedRange.Font.Name = "Tahoma"
ActiveWorkbook.ActiveSheet.UsedRange.Font.Size = 9
ActiveWorkbook.ActiveSheet.Cells.EntireRow.AutoFit
ActiveWorkbook.ActiveSheet.Cells.EntireColumn.AutoFit
End Sub |
|