导出到文本文件 [英] Export to text file

查看:106
本文介绍了导出到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

解决方案

Hi BO,


首先,确保在Excel VBA环境中添加了Access参考"Microsoft Access {version} Object Library"。

然后你可以将下面的代码附加到命令按钮:

 Sub OnBtttonClick()Dim accessApp As Access.Application Dim txtFilePath As String Dim txtFileName As String Dim tableName As String tableName =" TEST" txtFilePath = Application.ActiveWorkbook.Path'将char"/"替换为" - ",因为它是无效的文件名txtFileName = tableName&替换(日期,"/"," - ")和& " .TXT"设置accessApp = CreateObject(" Access.Application")Dim dbFilePath As String dbFilePath =" E:\Personal\Personal\Access\HelloAccess.accdb" accessApp.OpenCurrentDatabase(dbFilePath)accessApp.DoCmd.TransferText acExportDelim,"",tableName,txtFilePath& " \" &安培; txtFileNameEnd Sub 

您可以从以下文章中获得有关如何使用"TransferText"方法的更多信息。

http://msdn.microsoft.com/en-us/library/office/aa220768 (v = office.11​​)的.aspx


Hi everyone

解决方案

Hi BO,

First, make sure you have added the Access reference "Microsoft Access {version} Object Library" in your Excel VBA environment.
Then you can attach the code below to a command button:

Sub OnBtttonClick()    Dim accessApp As Access.Application    Dim txtFilePath As String    Dim txtFileName As String    Dim tableName As String    tableName = "TEST"txtFilePath = Application.ActiveWorkbook.Path    ‘replace the char "/" to "-" because it is an invalid file name    txtFileName = tableName & Replace(Date, "/", "-") & ".txt"    Set accessApp = CreateObject("Access.Application")    Dim dbFilePath As String    dbFilePath = "E:\Personal\Personal\Access\HelloAccess.accdb"    accessApp.OpenCurrentDatabase (dbFilePath)    accessApp.DoCmd.TransferText acExportDelim, "", tableName, txtFilePath & "\" & txtFileNameEnd Sub

You can get more information about how to use ‘TransferText’ method from the article below.
http://msdn.microsoft.com/en-us/library/office/aa220768(v=office.11).aspx


这篇关于导出到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆