加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

ACCESS中窗体记录导出到EXCEL等的方法

(2007-11-15 08:44:55)
标签:

access

excel

导出

分类: 计算机应用
可以用宏做,也可以用代码,用宏就是outputout,
代码也是,具体如下:
Docmd.OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding)
 
ObjectType 被输出对象的类型(表、查询还是窗体等……)
acOutputForm
acOutputFunction
acOutputModule
acOutputQuery
acOutputReport
acOutputServerView
acOutputStoredProcedure
acOutputTable
ObjectName 被输出对象的名字
OutputFormat  输出的格式
acFormatASP
acFormatDAP
acFormatHTML
acFormatIIS
acFormatRTF
acFormatSNP
acFormatTXT
acFormatXLS
  如果想导出成97-2003格式用 acSpreadsheetTypeExcel9
OutputFile 要输出文件的路径和完整名称。如果将该参数留空,Access 将提示指定输出文件名
AutoStart 逻辑值ture or false,导出时是否启动程序。例如,导出成xls时,是否启动excel。
TemplateFile 调用模版的路径和完整的名称。
需要注意的是导出时如果取消,ACCESS会报错,所以代码中需要加一段出错处理,一般这种错误的代码是2501.
示例:
Private Sub Command_Click()
 
On Error GoTo err_Command_Click
 
DoCmd.OutputTo
acOutputTable, "Employees",acFormatRTF, "D:\Employee.rtf", True
 
err_Command_Click:
If Err.Number = 2501 Then Cancel = True




Exit Sub
 
 
 
 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有