I'm using VBA in excel which finds if specific values are existing in files coded like XML files. The XML files are big (more than 100000 lines with few million characters) and to increase the speed I'm loading XML files to an array. Everything works for me when I use 100 XML files, however, if there are >200 XML files, the excel will consume too much RAM and the code fails with 'runtime error 7 out of memory'.
I'm thinking that I need just specific values from XML code which always starts with: ="
and ends with: "
, so if I remove everything else and keep only required text this will save a lot of consumed RAM.
For example, my XML file contains:
...
$<yiapcspvgdldm:Condition.ActionTypes>
<yiapcspvgdldm:ColorChange
BrushStyle="H1"
ColorChangeType="NormalColorChange"
Color="#00FFFFFF"
PropertyName="Foreground" />
<yiapcspvgdldm:Blinking
PropertyName="Foreground" />
<yiapcspvgdldm:Set
AttributeName="Visibility"
AttributeType="System"
To="{x:Static Visibility.Hidden}" />
</yiapcspvgdldm:Condition.ActionTypes>$
...
In this case I will need just:
H1
NormalColorChange
#00FFFFFF
Foreground
Foreground
Visibility
System
{x:Static Visibility.Hidden}
As I mentioned, each file contains >100000 lines, I tried to go through string's each line till EOF
,but this takes ages...
I tried SPLIT function, but this just splits the text and doesn't remove unwanted text.
I tried to find my answer here, but without success. Any help will be much appreciated.
Here is my extracted SUB:
Dim GrapicFiles(), GrapicText() As String
Dim PrjtFolder as string
Sub LoadXML()
Dim i, GraphCount As Integer
Dim Path, FileName As String
Dim objFSO, objTF As Object
Dim strIn As Variant
PrjtFolder="C:\temp\"
If Worksheets("Work").FilterMode Then Worksheets("Work").ShowAllData
GraphCount = Application.WorksheetFunction.CountA(Worksheets("Work").Range("B:B")) - 1
For i = 1 To GraphCount
DoEvents
FileName = Worksheets("Work").Cells(i + 1, 2).Value
Path = PrjtFolder & FileName & "\Main.xml"
'Load files to array
ReDim Preserve GrapicFiles(UBound(GrapicFiles) + 1)
ReDim Preserve GrapicText(UBound(GrapicText) + 1)
'Text Reading
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTF = objFSO.OpenTextFile(Path, 1)
strIn = objTF.readall
objTF.Close
Set objFSO = Nothing
Set objTF = Nothing
'>>>>>>>I will need something here to make my 'strIn' string smaller
'saving to array
GrapicFiles(i) = FileName
GrapicText(i) = strIn
Set strIn = Nothing
Next i
End Sub