I am now working one project using VB 6.0 to automate word application. The project will count the occurrence of the word/s in microsoft word application. But i stop since i get a problem on how to highlight the word that i am inputted in Text1.Text. I hope you can help me to finish my project guys. All i wanted is, I have to input a string in Text1.Text and when i clicked the commandbutton, this will count the occurrence and also this will highlight to microsoft word application based on the word or words that i am inputted in Text1.text...
Here is my code... The problem of this code, all of the text in the word application will be highlighted not the text that i am inputted in Text1.Text.. Please modified my code... There is no problem with the counting since it is correct already...
Code:Private Sub Command1_Click() On Error Goto ErrTrap Dim objWdRange As Word.Range Dim objWdDoc As Word.Document Dim count As Integer Dim wdText As String count = 0 wdText = Text1.Text Set objWdDoc = Application.ActiveDocument Set objWdRange = objWdDoc.Content ' set the color objWdDoc.Range.HighlightColorIndex = wdYellow With objWdRange.Find 'condition to set optionbutton to true If optHighlight.Value = True Then .Text = Text1.Text .Replacement.Text = "" .Execute Replace:= wdReplaceAll End If Do While .Execute(FindText:=wdText, Format:=False, _ MatchCase:=True, MatchWholeWord:=False, MatchAllWordForms:=False) = True count = count + 1 Loop End With MsgBox "There are " & count & " words found in this document", vbInformation Set objWdRange = Nothing Set objWdDoc = Nothing Exit Sub ErrTrap: If Err.Number = 429 Then Msgbox "You cannot start the counting operation, please open a document", vbOKOnly + vbExclamation, "No document opened" Else Msgbox "An error of " & Err.Number & " " has occured. This means " & Err.Description End If End Sub
hope you can help me....



Reply With Quote
