有一个这样的 csv 文件,我可以使用下面的代码轻松阅读它。但正如您所见,csv 中有多个 name1、group1、status1、name2、group2 等列。每个用户将有不同数量的列。我想知道是否有办法在我打电话的地方使用通配符,objRecordset.Fields.Item("Group1")
或者("Group%")
我是否可以自动增加数字直到找不到记录
用户名,域,站点,MCO,Name1,Group1,Status1,Name2,Group2,Status2,Name3,Group3,Status3 Paolina,AA,Athens,Greece,Adobe Acrobat Pro,ACROBAT009,Live,,,,,, George,AA,雅典,希腊,SpotFire 2.20,SPOTFIRE220,直播,,,,,,
option explicit
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
Dim strPathtoTextFile, objConnection, objRecordSet, objNetwork
Dim wshshell, Username
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
Set objNetwork = CreateObject("WScript.Network")
userName = objNetwork.UserName
strPathtoTextFile = "C:\Hunter\vbs\" 'must have a trailing \
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""
objRecordset.Open "SELECT * FROM Users.txt where [user name] like '" & UserName & "'", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
Do Until objRecordset.EOF
Wscript.Echo "Name: " & objRecordset.Fields.Item("User Name")
Wscript.Echo "Group: " & objRecordset.Fields.Item("Group1")
Wscript.echo "Status:" & objRecordset.Fields.Item("Status1")
objRecordSet.MoveNext
Loop