我正在嘗試編寫一個VBA過程來搜索文本文件中的用戶名以查找用戶的IP地址。舉例來說,如果我搜索Chris Trucker
,我希望在消息框中看到192.168.130.22
。VBA文本文件搜索
> 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
+ 1尼斯一個JFC –
+1,這也是一個很好的一個。 – Cylian
感謝您的幫助 –