Office中国论坛/Access中国论坛
标题:
用什么函数可以链接到EXCEL
[打印本页]
作者:
SUQUANJIN
时间:
2007-12-12 15:57
标题:
用什么函数可以链接到EXCEL
请教一下: 有时ACCESS和EXCEL及WORD都是配合着用的,,有一些数据和表格是用EXCEL做的,在ACCESS中要怎么样才能用命令打开EXCEL的工作表呢?
作者:
andymark
时间:
2007-12-12 16:05
下面是一个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
复制代码
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3