|
下面是一个ACCESS操作EXCEL的例子
- Sub FileImportFromExcel(ByVal sFile As String)
- Dim appExcel As Excel.Application
- Dim wbk As Excel.Workbook
- Dim wks As Excel.Worksheet
- Dim Rs As New ADODB.Recordset
- Dim Conn As New ADODB.Connection
- Dim I As Integer
- Dim J As Integer
- Dim StrWeekName As String
- Set appExcel = Excel.Application
- Set wbk = appExcel.Workbooks.Open(sFile)
- Set wks = appExcel.Worksheets("NB LIPC")
- Set Conn = CurrentProject.Connection
- On Error Resume Next
- Rs.Open "Select * from TemCommitFromExcel", Conn, adOpenDynamic, adLockOptimistic
- For I = 1 To 500
- If wks.Cells(I, 1).Value = "Technology" Then
- Rs.AddNew
- Rs.Fields("Year") = Me.CmbYear
- Rs.Fields("Site") = Me.TxtSite
- Rs.Fields("RequirementWeek") = Me.CmbRequirementWeek
- Rs.Fields("PartNumber") = Trim(wks.Cells(I, 5).Value)
- For J = 0 To 13
- StrWeekName = "WK" & J
- Rs.Fields(StrWeekName) = wks.Cells(I + 5, 2 + J).Value
- Next J
- Rs.Update
- End If
- Next I
- Set wks = Nothing
- wbk.Close True
- Set wbk = Nothing
- appExcel.Quit
- Set appExcel = Nothing
- Set Rs = Nothing
- Set Conn = Nothing
- Exit Sub
- End Sub
复制代码 |
|