ChrisGudrich
New Member
- Joined
- Sep 5, 2022
- Messages
- 3
- Office Version
- 365
- 2016
- Platform
- Windows
Dear Board Members,
First of all, I would like to praise the fantastic solutions that I have been able to implement with your help so far ... and so far without having to ask.
This time, unfortunately, neither the search nor presumed solutions from other problems solved my problem.
The following general conditions:
This "macro" searches XML files for certain invalid formats. This all works perfectly, at least until mid returns the value 0 / Zero and then aborts with runtime error 5.
Here is the complete code:
The following code line is ejected as faulty:
As a solution, I would like to think of a preliminary check that first checks whether 0 / Zero is returned and then continues to run in the loop.
Thank you very much!
Chris
First of all, I would like to praise the fantastic solutions that I have been able to implement with your help so far ... and so far without having to ask.
This time, unfortunately, neither the search nor presumed solutions from other problems solved my problem.
The following general conditions:
This "macro" searches XML files for certain invalid formats. This all works perfectly, at least until mid returns the value 0 / Zero and then aborts with runtime error 5.
Here is the complete code:
VBA Code:
Sub Analyse_Format_Bold()
Dim strLine As String
Dim f As Integer
Dim lngLine As Long
Dim blnFound As Boolean
Dim strFileName
Dim WhichRowAmI As Integer
Dim strQuote
Dim SplitCatcher As Variant
Dim Counter As Integer
Dim i As Integer
Dim openPos As Integer
Dim closePos As Integer
Dim str1 As String
f = FreeFile
' Select cell A2, *first line of data*.
Range("B2").Select
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
strFileName = Worksheets("Data").Range("B" & ActiveCell.Row)
strQuote = Chr$(34)
Const strSearch = "<emphasis role=" & """" & "default" & """" & ">"
Const strSearch2 = "<entry><emphasis role=" & """" & "default" & """" & ">"
Const strSearch3 = "<entry><para><emphasis role=" & """" & "default" & """" & ">"
Const strSearch4 = "<title><emphasis role=" & """" & "default" & """" & ">"
Const strSearch5 = "<emphasis role=" & """" & "default" & """" & ">***"
Open strFileName For Input As #f
'Schleife 1
Do While Not EOF(f)
lngLine = lngLine + 1
Line Input #f, strLine
If InStr(1, strLine, strSearch, vbBinaryCompare) > 0 Then
If InStr(1, strLine, strSearch2, vbBinaryCompare) > 0 Then
Range("L" & ActiveCell.Row).Value = "NoMatch"
' Step down 1 row from present location.
Range("B" & ActiveCell.Row).Select
ActiveCell.Offset(1, 0).Select
Close #f
Exit Do
ElseIf InStr(1, strLine, strSearch3, vbBinaryCompare) > 0 Then
Range("L" & ActiveCell.Row).Value = "NoMatch"
' Step down 1 row from present location.
Range("B" & ActiveCell.Row).Select
ActiveCell.Offset(1, 0).Select
Close #f
Exit Do
ElseIf InStr(1, strLine, strSearch4, vbBinaryCompare) > 0 Then
Range("L" & ActiveCell.Row).Value = "NoMatch"
' Step down 1 row from present location.
Range("B" & ActiveCell.Row).Select
ActiveCell.Offset(1, 0).Select
Close #f
Exit Do
ElseIf InStr(1, strLine, strSearch5, vbBinaryCompare) > 0 Then
Range("L" & ActiveCell.Row).Value = "NoMatch"
' Step down 1 row from present location.
Range("B" & ActiveCell.Row).Select
ActiveCell.Offset(1, 0).Select
Close #f
Exit Do
Else
Range("L" & ActiveCell.Row).Value = "Match"
SplitCatcher = Split(strLine, "<emphasis role=" & """" & "default" & """" & ">")
For Counter = 0 To UBound(SplitCatcher)
If i >= 1 Then
strLine = SplitCatcher(Counter)
End If
openPos = InStr(strLine, "<emphasis role=" & """" & "default" & """" & ">")
closePos = InStr(strLine, "</emphasis>")
str1 = Mid(strLine, openPos + 1, closePos - openPos - 1)
str1 = Replace(str1, "<emphasis role=" & """" & "default" & """" & ">", "")
If InStr(1, str1, "<emphasis role=" & """" & "italic" & """" & ">") >= 0 Then
str1 = Replace(str1, "<emphasis role=" & """" & "italic" & """" & ">", "")
End If
Range("AJ" & ActiveCell.Row).Value = Range("AJ" & ActiveCell.Row).Value & str1 & ", "
i = i + 1
Next
blnFound = True
If Not Range("AJ" & ActiveCell.Row).Value = "" Then
Range("AJ" & ActiveCell.Row).Value = Left(Range("AJ" & ActiveCell.Row).Value, Len(Range("AJ" & ActiveCell.Row).Value) - 3)
End If
' Step down 1 row from present location.
Range("B" & ActiveCell.Row).Select
ActiveCell.Offset(1, 0).Select
Close #f
Exit Do
End If
ElseIf Sheets("Data").Range("H" & ActiveCell.Row).Value = "N/A" Then
Range("L" & ActiveCell.Row).Value = "N/A"
' Step down 1 row from present location.
Range("B" & ActiveCell.Row).Select
ActiveCell.Offset(1, 0).Select
Close #f
Exit Do
Else
Range("L" & ActiveCell.Row).Value = "NoMatch"
' Step down 1 row from present location.
Range("B" & ActiveCell.Row).Select
ActiveCell.Offset(1, 0).Select
Close #f
Exit Do
End If
Loop
Loop
End Sub
The following code line is ejected as faulty:
VBA Code:
str1 = Mid(strLine, openPos + 1, closePos - openPos - 1)
As a solution, I would like to think of a preliminary check that first checks whether 0 / Zero is returned and then continues to run in the loop.
Thank you very much!
Chris