设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1001|回复: 1
打印 上一主题 下一主题

[Access本身] 用什么函数可以链接到EXCEL

[复制链接]
跳转到指定楼层
1#
发表于 2007-12-12 15:57:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请教一下:  有时ACCESS和EXCEL及WORD都是配合着用的,,有一些数据和表格是用EXCEL做的,在ACCESS中要怎么样才能用命令打开EXCEL的工作表呢?
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2007-12-12 16:05:25 | 只看该作者
下面是一个ACCESS操作EXCEL的例子
  1. Sub FileImportFromExcel(ByVal sFile As String)

  2. Dim appExcel As Excel.Application
  3. Dim wbk As Excel.Workbook
  4. Dim wks As Excel.Worksheet
  5. Dim Rs As New ADODB.Recordset
  6. Dim Conn As New ADODB.Connection
  7. Dim I As Integer
  8. Dim J As Integer
  9. Dim StrWeekName As String

  10. Set appExcel = Excel.Application
  11. Set wbk = appExcel.Workbooks.Open(sFile)

  12. Set wks = appExcel.Worksheets("NB LIPC")

  13. Set Conn = CurrentProject.Connection

  14. On Error Resume Next

  15. Rs.Open "Select * from TemCommitFromExcel", Conn, adOpenDynamic, adLockOptimistic

  16. For I = 1 To 500

  17. If wks.Cells(I, 1).Value = "Technology" Then
  18. Rs.AddNew
  19. Rs.Fields("Year") = Me.CmbYear
  20. Rs.Fields("Site") = Me.TxtSite
  21. Rs.Fields("RequirementWeek") = Me.CmbRequirementWeek
  22. Rs.Fields("PartNumber") = Trim(wks.Cells(I, 5).Value)

  23. For J = 0 To 13
  24. StrWeekName = "WK" & J
  25. Rs.Fields(StrWeekName) = wks.Cells(I + 5, 2 + J).Value
  26. Next J

  27. Rs.Update
  28. End If

  29. Next I

  30. Set wks = Nothing
  31. wbk.Close True
  32. Set wbk = Nothing
  33. appExcel.Quit
  34. Set appExcel = Nothing
  35. Set Rs = Nothing
  36. Set Conn = Nothing

  37. Exit Sub


  38. End Sub
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-12-1 19:48 , Processed in 0.134399 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表