更新时间:2023-01-23 09:40:37
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 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 SubYou 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