|
Dim xlApp As Excel.Application '定义EXCEL类
Dim xlBook As Excel.Workbook '定义工件簿类
Dim xlSheet As Excel.Worksheet '定义工作表类
If Dir("D:\temp\excel.bz") = "" Then '判断EXCEL是否打开
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = True '设置EXCEL可见
Set xlBook = xlApp.Workbooks.Open("D:\temp\bb.xls") '打开EXCEL工作簿
Set xlSheet = xlBook.Worksheets(1) '打开EXCEL工作表
xlSheet.Activate '激活工作表
Dim sql As String
Dim rs As New ADODB.Recordset
sql = "select [Start Time],date from [Log in/out Information] where [Staff ID]='001'"
rs.LockType = adLockOptimistic
rs.CursorLocation = adUseClient
rs.Open sql, CurrentProject.Connection
rs.MoveLast
If rs.RecordCount < 1 Then
MsgBox ("Error 没有记录!")
End If
rs.MoveFirst
Do Until rs.EOF
If rs("date") = "2010-1-1" Then‘目的当date=2010-1-1时,在xlSheet.Cells(8, 5) 填入对应的start time
xlSheet.Cells(8, 5) = "rs([start time])"
Else
xlSheet.Cells(8, 5) = "no"
End If
rs.MoveNext
Loop
xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL中的启动宏
Else
MsgBox ("EXCEL已打开")
End If
End Sub |
|