I'm hoping that someone might be able to help. The submacro needs to accept a word from the user, then search TextBox3 for instances of that word, then make them bold.
(I'm trying to modify code that I have used in Excel)
Private Sub btnSearchText_Click()
' Provide option to search for specific words and make them bold
Dim sFind As String
Dim rTextBox As Range
Dim rng As Range
Dim lCount As Long
Dim iLen As Integer
Dim iFind As Integer
Dim iStart As Integer
On Error Resume Next
Set rng = ActiveDocument.UsedRange. _
TextBox3
On Error GoTo ErrHandler
If rng Is Nothing Then
MsgBox "There is no text", vbExclamation + vbOKOnly, "Triage Hub"
GoTo ExitHandler
End If
sFind = Application.InputBox("What do you want to make BOLD?", "Triage Hub", "", Type:=2)
If sFind = "" Then
MsgBox "No text was requested", vbExclamation + vbOKOnly, "Triage Hub"
GoTo ExitHandler
End If
iLen = Len(sFind)
lCount = 0
For Each rTextBox In rng
With rTextBox
iFind = InStr(.Value, sFind)
Do While iFind > 0
.Characters(iFind, iLen).Font.Bold = True
lCount = lCount + 1
iStart = iFind + iLen
iFind = InStr(iStart, .Value, sFind)
Loop
End With
Next
If lCount = 0 Then
MsgBox "There were no occurrences of" & _
vbCrLf & "' " & sFind & " '" & _
vbCrLf & "to make bold.", vbExclamation + vbOKOnly, "Triage Hub"
ElseIf lCount = 1 Then
MsgBox "One occurrence of" & _
vbCrLf & "' " & sFind & " '" & _
vbCrLf & "was made bold.", vbInformation + vbOKOnly, "Triage Hub"
Else
MsgBox lCount & " occurrences of" & _
vbCrLf & "' " & sFind & " '" & _
vbCrLf & "were made bold.", vbInformation + vbOKOnly, "Triage Hub"
End If
ExitHandler:
Set rCell = Nothing
Set rng = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub