一些抛光后:
Private Sub GetFileInfo()
Dim fso As New FileSystemObject, strText As Variant, i As Integer
Dim X(0 To 2) As String, Y(0 To 2) As String, B, E As Variant
'get header string from xml file
'FName (file name) was ascertained by a previous sub and is made public
Set strText = fso.OpenTextFile(FName, ForReading, False)
'header string is in second (i = 2) line of file
For i = 1 To 2: [A1] = strText.ReadLine: Next: strText.Close: Set fso = Nothing
'User Oded's search and extract routine
X(0) = "IDREF=": X(1) = "Start=": X(2) = "Tags="
For i = LBound(X(), 1) To UBound(X(), 1)
B = InStr(1, [A1], X(i)) + Len(X(i)) + 1 ' + 1 includes trailing " character
E = InStr(B, [A1], " ") - 1 ' - 1 includes leading " character
'required if a search string in X() is at the end of the header which ends with a ">"
If (InStr(B, [A1], " ") - 1) < 0 Then E = InStr(B, [A1], ">")
Y(i) = Mid([A1], B, E - B)
Next
[D1] = "Test = " & Y(0)
[D2] = "Tested on : " & Left(Y(1), 10) & " at " & Mid(Y(1), 12, 8)
[D2] = [D2] & " - " & Y(2)
End Sub
来源
2014-10-12 12:40:57
Dan
感谢Oded,它的工作就像一个魅力!!!!!!!!!!!!这是最终结果:Sub Extract() Dim X(0 To 2)As String,Y(0 To 2)As String,FileType,DT,SN As Variant,B,E As Variant X(0)=“对于I = LBound(X(),1)到UBound(X(),1) B = InStr(1) ,范围(“A6”),值(X(i))+ Len(X(i))+ 1 E = InStr(B,范围(“A6”)值,“”) - 1 Y )=中等(范围(“A6”),值,B,E-B) Next [D1] =“Test =”&Y(0):[D2] =“测试:”&Left 1),10)&“at”&Mid(Y(1),12,8):[D2] = [D2]&“ - ”&Y(2) End Sub – Dan 2014-10-12 11:27:57
并且在一些抛光后: – Dan 2014-10-12 12:29:48