vba - 在 .txt 文件 VBA 中搜索用户提供的字符串
问题描述
我有以下代码,它返回文件夹目录中 .txt 文件的所有文件名。我想添加到此代码以打开 txt 文件并搜索用户提供的字符串,如果在文件中找到该字符串,则返回 true 或 false。
任何帮助将非常感激。
Sub VBAF1_List_All_TXT_Files_Using_Dir()
'Variable Declaration
Dim sFilePath As String
Dim sFileName As String
Dim sUserString As String
'Specify File Path
sFilePath = "C:\Users\d85307\Documents\Automation Anywhere Files\Automation Anywhere\My Docs\UK\Vehicle Delivery\ATDC\Log"
' sUserString =
'Check for back slash
If Right(sFilePath, 1) <> "\" Then
sFilePath = sFilePath & "\"
End If
sFileName = Dir(sFilePath & "*.txt")
Do While Len(sFileName) > 0
If Right(sFileName, 3) = "txt" Then
'Display file name in immediate window
Debug.Print sFileName
End If
'Set the fileName to the next available file
sFileName = Dir
Loop
End Sub
解决方案
推荐阅读
- javascript - 是否可以在不提示“离开此页面”或“留在此页面”选项的情况下防止刷新浏览器?
- java - Jav8:计算时间戳的经过时间
- c# - Asp.net core 2.1 基于角色的授权不适用于 JWT
- java - JAVA 如何获得接受父类及其所有扩展类的方法?
- windows - 如何在 Powershell 中进行 LM 哈希
- assembly - 使用 PIC16F18326 进行背靠背 UART 传输 - 跳过字节
- couchdb - 元素数组中字符串上的 CouchDB 查询选择器
- node.js - 命令 json-server --watch db.json 不起作用 - 它返回“'json-server' command not found”
- python - Pandas Plot:带索引的散点图
- javascript - 导出的 Javascript 对象与 json 文件