I have the code below which searches through an html file and extracts the names of all the images in the html code. The image names are written to an xml file and each image name has a set of xml tags added with it.
The problem is that I don't want to add an image name to the xml file if it has been added previously. I don't know if I can search the xml file or if I need a separate file that is an array or a collection, or . . ??
Code:
Function GetRegExResult(strInputData As String) As String
Dim Match, Matches
Dim RegExp As Object
Dim strMatchesFile As String
Dim sRegPath As String
Dim sRegImageFile As String
sRegPath = ActiveDocument.Path
sRegImageFile = sRegPath + "\ImageNames.txt"
strMatchesFile = sRegImageFile
Set RegExp = CreateObject("VBScript.RegExp")
With RegExp
.Global = True
.IgnoreCase = True
.Pattern = "<img\s*src=""([^""]*)"""
End With
Set Matches = RegExp.Execute(strInputData) ' Execute search.
For Each Match In Matches
Dim strMatchOrig As String
Dim intMatchLength As Integer
intMatchLength = Len(Match)
intMatchLength = intMatchLength - 11
strMatchOrig = Match
strMatchOrig = Mid(strMatchOrig, 11, intMatchLength)
hFile = FreeFile
Open strMatchesFile For Append As #hFile
Print #hFile, "<Uses>" + vbNewLine _
+ "<FileName>" + strMatchOrig + "<" + Chr(47) + "FileName>" + vbNewLine _
+ "<MD5>456789<" + Chr(47) + "MD5>" + vbNewLine _
+ "<" + Chr(47) + "Uses>"
Close #hFile
Next
End Function