EXCEL VBA:访问“Debug.Print”
我正在使用类似下面的代码来调用文件夹中的名称:
Sub PrintFilesNames() Dim file As String file = Dir$(PathToFolder) While (Len(file) > 0) Debug.Print file file = Dir Wend End Sub
它将所有名称打印到直接文件夹中。 现在有没有一种方法可以使用VBAsearch已经打印的文件,select一些包含特定子string,然后将其粘贴到Excel表中?
谢谢!
迈克尔
您可以使用Dir()中的模式来执行此操作:
Sub PrintFilesNames() Dim file As String, c as range Set c = thisworkbook.sheets("Sheet1").Range("A1") file = Dir$(PathToFolder & "\*yoursubstring*.xls") While (Len(file) > 0) c.value = file Set c = c.offset(1,0) file = Dir Wend End Sub