1
A
回答
1
Sub DAOFromExcelToAccess()
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim db As Database, rs As Recordset, r As Long
Set db = OpenDatabase("C:\FolderName\DataBaseName.mdb")
' open the database
Set rs = db.OpenRecordset("TableName", dbOpenTable)
' get all records in a table
r = 3 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("FieldName1") = Range("A" & r).Value
.Fields("FieldName2") = Range("B" & r).Value
.Fields("FieldNameN") = Range("C" & r).Value
' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub
0
你有没有考虑过其他方法?在Access中附加Excel工作表很容易,然后使用make table查询将数据添加到新表或现有表中,这样可以避免编码。
相关问题
- 1. SSIS Excel数据源 - 是否可以重写列数据类型?
- 2. 是否可以将数据从Excel导入jQGrid?
- 3. 是否可以通过内存从Excel中导入数据?
- 4. 是否可以从批处理文件写入excel文件?
- 5. 是否可以从python创建/编辑excel宏?
- 6. 是否可以将以下lisp宏编写为函数?
- 7. 是否可以插入freemarker宏?
- 8. 是否可以重写向后导航?
- 9. 是否可以使用Extjs4将数据写入JSON?
- 10. 是否可以将数据写入wpf中的集合?
- 11. 是否可以使用JavaScript将数据写入Google表单?
- 12. Spark在写入时是否可以使用SQL数据库?
- 13. SAS宏以纵向数据
- 14. 将数据框写入excel以标题
- 15. 可以excel读写phpmyadmin数据库吗?
- 16. 是否可以向Firebird blob写入大字符串?
- 17. Python csv.writer - 是否可以写入变量?
- 18. 是否可以使用.NET写入CD?
- 19. 是否可以写入远程HDFS?
- 20. 是否可以通过外部命令在Excel中运行宏?
- 21. 是否可以为Excel 2007编写dset函数
- 22. 是否可以向Roboguice注入尺寸?
- 23. Excel Services是否支持宏?
- 24. 将数据从NSArray写入Excel文件?
- 25. .NET - 是否可以直接将数据表写入SQL数据库?
- 26. 在Excel中将宏写入数据日志
- 27. Excel宏 - 从数组读取数据
- 28. 是否可以编写一个通过excel文档运行数据的服务?
- 29. 是否可以编写这些pure_assert和const_assert宏?
- 30. 是否可以向数据透视表(Excel Interop)添加手动分页符?