导出到文本文件

编程入门 行业动态 更新时间:2024-10-11 17:29:55
本文介绍了导出到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好

解决方案

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"方法的更多信息。 msdn.microsoft/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. msdn.microsoft/en-us/library/office/aa220768(v=office.11).aspx

更多推荐

导出到文本文件

本文发布于:2023-11-24 05:59:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624172.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本文件   导出到

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!