我正在尝试编写一个 VBA 程序,在文本文件中搜索用户名以查找用户的 IP 地址。例如,给定下面的输入,如果我搜索Chris Trucker
我想192.168.130.22
在消息框中看到。
> 192.168.2.151,Super Fly,ABC\Flys,2012-05-18 16:11:29
> 192.168.2.200,Rain,ABC\rain,2012-05-17 15:42:05
> 192.168.2.210,Snow,ABC\Snow,2012-05-16 08:24:39
> 192.168.2.78,Wind,ABC\wind,2012-05-02 19:24:06
> 192.168.130.21,Mike Jordan,ABC\Jordanm,2012-05-18 17:28:11
> 192.168.130.22,Chris Trucker,ABC\Truckerc,2012-05-18 17:28:11
> 192.168.130.23,Chris Jackson,ABC\JacksonC,2012-05-18 17:04:39
尝试了以下,但它是 VBScript
Const ForReading = 1
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "JacksonC"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("\\server\tsusers\Users.txt", ForReading)
Do Until objFile.AtEndOfStream
strSearchString = objFile.ReadLine
osakapc = Left(strSearchString,14)
Set colMatches = objRegEx.Execute(strSearchString)
If colMatches.Count = 1 Then
For Each strMatch in colMatches
Next
End If
Loop