I have created a template that works a bit like Synonyms in Word. My first macro which is the part i am having problems with takes a bit too long to run. When I run the Macro it checks to see if any words in the current document match those of a text file (word list) that I have. if it finds a match it underlines the word ready for me to run another Macro on it. The text file has around 1000 rows and each row has 2-5 words on it sepearated by a tab.
I have been around looking for help and the code I have pasted below is the fastest so far (but still a bit slow). Does anyone have any ideas to speed it up even more?
Sub FindHomonyms()
Dim oRg As Range
Dim LineFromFile As String, LineString As String
Dim WordArray As Variant
Dim indx As Integer, LparenPos As Integer, RparenPos As Integer
Dim WholeDocument As String
Open “c:tempdata.txt” For Input As #1
Do While Not EOF(1)
Line Input #1, LineString
LparenPos = InStr(LineString, “(“)
Do While LparenPos > 0
RparenPos = InStr(LparenPos, LineString, “)”)
If RparenPos > 0 Then
LineString = Left(LineString, LparenPos – 2) & _
Right(LineString, Len(LineString) – RparenPos)
LparenPos = InStr(LineString, “(“)
End If
Loop
LineFromFile = LineFromFile & vbTab & LineString
Loop
Close #1
WordArray = Split(LineFromFile, vbTab)
Set oRg = ActiveDocument.Range
Application.ScreenUpdating = False
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Font.Underline = wdUnderlineWavyHeavy
.Replacement.Text = “^&” ‘ 0 Then
.Text = WordArray(indx)
.Execute Replace:=wdReplaceAll
End If
StatusBar = UBound(WordArray) – indx
DoEvents
Next indx
End With
Application.ScreenUpdating = True
End Sub
If I haven’t explained anything clear enough please post back
Richi