ifix vba 读取计算机中的txt文件,截取字符串显示

利用vba脚本,使用Scripting.FileSystemObject对象可以实现对文本文件的操作,下面以一个朋友的实际例子为例将截获的字符串进行页面显示。

Private Sub CommandButton3_Click()
Dim fso
Dim txtfile
Dim msrt3 As String
Dim ma3() As String
Dim msrt1, ma1, msrt2, ma2, tempp, tempp2, i, a, j
Set fso = CreateObject("Scripting.FileSystemObject")
'If fso.FileExists("D:\AQSS.txt") Then
'/*共享方式读远程PC
If fso.FileExists("E:\KJ110Nweb.txt") Then
'MsgBox "文件存在"
'If fso.FileExists("D:\\Export&Import\\"&CStr(a)&".txt") Then
'Set txtfile = fso.OpenTextFile("D:\AQSS.txt")
Set txtfile = fso.OpenTextFile("E:\KJ110Nweb.txt")
'MsgBox "开始读取"
For i = 1 To 380
If Not txtfile.AtEndOfLine Then
txtfile.SkipLine
'1#瓦斯
If i = 9 - 1 Then
msrt3 = "" & txtfile.ReadLine & ""
ma3 = Split(msrt3, ",", -1, 1)
'Fix32.Fix.ABC.A_CV = ma3(0)
'Fix32.Fix.ABCD.A_CV = ma3(7)
'Fix32.Fix.ABBB.A_CV = ma3(8)
'Fix32.Fix.ABCDE.A_CV = ma3(9)
writevalue ma3(0), "Fix32.Fix.Fault-1.A_DESC"
writevalue ma3(7), "Fix32.Fix.Fault-2.A_DESC"
writevalue ma3(8), "Fix32.Fix.Fault-4.A_DESC"
writevalue ma3(9), "Fix32.Fix.Fault-5.A_DESC"



End If


End If
Next


'MsgBox "导入数据成功"
txtfile.Close
Else
'MsgBox "文件不存在"
End If
End Sub

注:ma3()为字符串数组,用来存储split函数将每行readline方法截获的行的信息进行分类。

猜你喜欢

转载自blog.csdn.net/sheng1522098487/article/details/80857319
vba