我是VBA的新手,所以请耐心等待。我需要将文件夹中的.txt文件重命名为永不更改的文件名(它在Access中链接为表)。运行一个宏,将数据刮到另一个表中,然后对文件夹中的所有文件重复该过程(循环)。下面的代码重命名第一个文件并运行该宏,但是据我所知。它无法正确循环。任何帮助将不胜感激!
def search(term):
s = Search().filter('match_phrase', title=term)
response = s.execute()
return response
答案 0 :(得分:0)
您的Adhok解决方案是
Function process()
'
Dim tmp As String
tmp = Dir("C:\Users\Calhoun\Documents\REPORTING\Correspondence\*.txt")
Do While tmp > ""
on error resume next
Kill "C:\Users\Calhoun\Documents\REPORTING\Correspondence\STATIC_FILE_NAME.txt"
On Error Goto 0
Name "C:\Users\Calhoun\Documents\REPORTING\Correspondence\" & tmp As "C:\Users\Calhoun\Documents\REPORTING\Correspondence\STATIC_FILE_NAME.txt"
DoCmd.RunMacro "RunQueries"
tmp = Dir
Loop
End Function
就像Mathieu Guindon在评论中提到的那样,在循环内使用Dir
打破了循环外的Dir