0

我有这个查询,我必须在 excel 中运行多次,我需要更改其中的文件列表。

   select * from files 
   where 
   filename in ('filename1','filename2')

所以我在 TEMP 中的查询文件名中有一个 TEMP,我想循环并获取所有文件列表的结果。我唯一的问题是将 .txt 读入 TEMP 并对 txt 文件中的所有文件名执行一次查询。我知道如何逐行读取文件,所以没有帮助。

我想从中读取列表的文本文件就像

文件名 1 文件名 2 。. . . 文件名15000

是的一些大数字。

    dim filelist as string
    dim filelistpath as string
    sqlstring = "select count(*) from files where  filename in TEMP"
    filelistpath = "c:\"

    open filelistpath for input as #1
    do while not EOF(1)
    line input #1,text
    'here i should construct my file list to replace the TEMP below, how ?
    loop
    close #1 
    sqlstring = replace(sqlstring,TEMP, filelist)

    set rs = conn.execute(sqlstring)

    'here i want to write the result to my excel sheet, how ?

谢谢

4

1 回答 1

0

I formatted the text and just read it like that as a whole

Function GetText(sFile As String) As String
   Dim nSourceFile As Integer, sText As String

 ''Close any open text files
  Close

  ''Get the number of the next free text file
   nSourceFile = FreeFile

  ''Write the entire file to sText
   Open sFile For Input As #nSourceFile
   sText = Input$(LOF(1), 1)
   Close

   GetText = sText
   End Function
于 2013-09-28T12:45:11.187 回答