richiwatts
Technical User
I hope this is understandable:
I have a template that scans a current Word document for words that match those in a separate text file.
If a match is found it highlights the word and I can then run another Macro on the highlighted word which will pop up a window and show me all the other words on the same line in the text file, I can then choose another word – a bit like synonyms.
The first couple of lines in the text file looks like this:
acclamation acclimation
acts ax (*) axe (*)
ad add
adds ads adze (*) adz (*)
adieu ado
aerie (*) eyrie (*) airy
Words that are followed by “space(*)” represent words that are spelt differently but mean the same.
The problem I have is that I need (*) to show in the window that pops up but not placed into the Word document if I select that word. e.g if the word “acts” in my document was highlighted and I run my second Macro the window that pops up should look like this:
acts
ax (*)
axe (*)
If I then decide to change the word to “ax” I can select it and it would replace “acts” with “ax” and not “ax (*).
I already have the code that makes the idea work but the code I have doesn’t show the (*) in the window. How would I change it so that it does show up in the window but not in the document I would be grateful if someone could take a look through my code or post back if something is not clear.
Private Sub UserForm_Activate()
Dim LineString As String
Dim TextFromDocument As String
Dim path As String
Dim WordArray As Variant
Dim bFound As Boolean, nFoundPos As Integer
Dim indx As Integer, LparenPos As Integer, RparenPos As Integer
If Selection.FormattedText.HighlightColorIndex <> wdTurquoise Then
Me.Hide
MsgBox "Please make sure the cursor is over a highlighted word"
bOK = False
Exit Sub
End If
TextFromDocument = LCase(HomonymRange.Text)
' Use your own path and file name
path = ThisDocument.path
Open path & Application.PathSeparator & "data.txt" For Input As #1
bFound = False
Do While (Not EOF(1)) And (Not bFound)
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
WordArray = Split(LineString, vbTab)
For indx = 0 To UBound(WordArray)
If WordArray(indx) = TextFromDocument Then
bFound = True
Exit For
End If
Next indx
Loop
Close #1
If Not bFound Then
Me.Hide
MsgBox "Could not find homonyms for " & TextFromDocument
bOK = False
Exit Sub
End If
lbSuggestions.List = WordArray
End Sub
I have a template that scans a current Word document for words that match those in a separate text file.
If a match is found it highlights the word and I can then run another Macro on the highlighted word which will pop up a window and show me all the other words on the same line in the text file, I can then choose another word – a bit like synonyms.
The first couple of lines in the text file looks like this:
acclamation acclimation
acts ax (*) axe (*)
ad add
adds ads adze (*) adz (*)
adieu ado
aerie (*) eyrie (*) airy
Words that are followed by “space(*)” represent words that are spelt differently but mean the same.
The problem I have is that I need (*) to show in the window that pops up but not placed into the Word document if I select that word. e.g if the word “acts” in my document was highlighted and I run my second Macro the window that pops up should look like this:
acts
ax (*)
axe (*)
If I then decide to change the word to “ax” I can select it and it would replace “acts” with “ax” and not “ax (*).
I already have the code that makes the idea work but the code I have doesn’t show the (*) in the window. How would I change it so that it does show up in the window but not in the document I would be grateful if someone could take a look through my code or post back if something is not clear.
Private Sub UserForm_Activate()
Dim LineString As String
Dim TextFromDocument As String
Dim path As String
Dim WordArray As Variant
Dim bFound As Boolean, nFoundPos As Integer
Dim indx As Integer, LparenPos As Integer, RparenPos As Integer
If Selection.FormattedText.HighlightColorIndex <> wdTurquoise Then
Me.Hide
MsgBox "Please make sure the cursor is over a highlighted word"
bOK = False
Exit Sub
End If
TextFromDocument = LCase(HomonymRange.Text)
' Use your own path and file name
path = ThisDocument.path
Open path & Application.PathSeparator & "data.txt" For Input As #1
bFound = False
Do While (Not EOF(1)) And (Not bFound)
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
WordArray = Split(LineString, vbTab)
For indx = 0 To UBound(WordArray)
If WordArray(indx) = TextFromDocument Then
bFound = True
Exit For
End If
Next indx
Loop
Close #1
If Not bFound Then
Me.Hide
MsgBox "Could not find homonyms for " & TextFromDocument
bOK = False
Exit Sub
End If
lbSuggestions.List = WordArray
End Sub