0

テーブル名を一覧表示するコードがありますが、これをテキスト ファイルにエクスポートするにはどうすればよいですか?

 For Each tbl In db.TableDefs
 If Left$(tbl.Name, 4) <> "MSys" Then
   Debug.Print tbl.Name & "      " & tbl.DateCreated & "      " & _
    tbl.LastUpdated & "     " & tbl.RecordCount
4

3 に答える 3

0

単純なファイル I/O を使用して、テキスト ファイルに書き込むことができます。MSDN: Write# ステートメント

そのページの例を次に示します。

Open "TESTFILE" For Output As #1    ' Open file for output.
Write #1, "Hello World", 234    ' Write comma-delimited data.
Write #1,    ' Write blank line.

Dim MyBool, MyDate, MyNull, MyError
' Assign Boolean, Date, Null, and Error values.
MyBool = False: MyDate = #2/12/1969#: MyNull = Null
MyError = CVErr(32767)
' Boolean data is written as #TRUE# or #FALSE#. Date literals are
' written in universal date format, for example, #1994-07-13#
 'represents July 13, 1994. Null data is written as #NULL#.
' Error data is written as #ERROR errorcode#.
Write #1, MyBool; " is a Boolean value"
Write #1, MyDate; " is a date"
Write #1, MyNull; " is a null value"
Write #1, MyError; " is an error value"
Close #1    ' Close file.

ファイル名と拡張子を「C:\SomeFolder\myfile.txt」などに変更します。

FileSystemObjectDavidが提供したリンクに示されているように、を使用するなど、これを行うための他のより洗練された方法があります。

于 2013-07-22T17:45:33.033 に答える
0

テキスト ファイルの作成方法については、MSDN の記事を参照してください。

http://msdn.microsoft.com/en-us/library/aa265018(v=vs.60).aspx

ニーズに合わせてわずかに変更されています。定義するために微調整する必要がありdbますTableDefs

Sub CreateAfile
    Dim fs as Object, a as Object
    Dim lineText as String
    #Create and open text file for writing:
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile("c:\testfile.txt", True)
    '#Iterate over your TableDefs
    For Each tbl In db.TableDefs
         If Left$(tbl.Name, 4) <> "MSys" Then
              lineText = tbl.Name & "      " & tbl.DateCreated & "      " & _
              tbl.LastUpdated & "     " & tbl.RecordCount

              '# Adds a line to the text file
              a.WriteLine(lineText)
         End If
    Next
    '#Close the textfile
    a.Close
End Sub
于 2013-07-22T17:46:25.587 に答える