sassora
03-27-2008, 12:35 PM
I made some code to find words, make them bold and put a hyphen after them. I messed around with it and now it doesn't work. The error talks about end with. I'm sure it's something small but I can't spot what it is!
Here is the code
Sub sd()
Dim iCount As Integer
Dim i As Integer
Dim j As Integer
Dim sResponse(5)
sResponse(1) = "Enjoying and achieving"
sResponse(2) = "Being Healthy"
sResponse(3) = "Staying Safe"
sResponse(4) = "Positive Contribution"
sResponse(5) = "Organisation"
j = 1
Do Until j = 5
If sResponse(j) > "" Then
' Set the counter to zero for each loop
iCount = 0
Application.ScreenUpdating = False
With Selection
.HomeKey Unit:=wdStory
With .Find
'.ClearFormatting
.Text = sResponse(j)
' Loop until Word can no longer
' find the search string and
' count each instance
Do While .Execute
iCount = iCount + 1
Selection.MoveRight
Loop
End With
'Puts in the bold names and inserts a hyphen
For i = 1 To iCount
Selection.Find.ClearFormatting
With Selection.Find
.Text = sResponse(j)
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.Font.Bold = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=" - "
Next i
Application.ScreenUpdating = True
End If
j = j + 1
Loop
End Sub
Any ideas?
Here is the code
Sub sd()
Dim iCount As Integer
Dim i As Integer
Dim j As Integer
Dim sResponse(5)
sResponse(1) = "Enjoying and achieving"
sResponse(2) = "Being Healthy"
sResponse(3) = "Staying Safe"
sResponse(4) = "Positive Contribution"
sResponse(5) = "Organisation"
j = 1
Do Until j = 5
If sResponse(j) > "" Then
' Set the counter to zero for each loop
iCount = 0
Application.ScreenUpdating = False
With Selection
.HomeKey Unit:=wdStory
With .Find
'.ClearFormatting
.Text = sResponse(j)
' Loop until Word can no longer
' find the search string and
' count each instance
Do While .Execute
iCount = iCount + 1
Selection.MoveRight
Loop
End With
'Puts in the bold names and inserts a hyphen
For i = 1 To iCount
Selection.Find.ClearFormatting
With Selection.Find
.Text = sResponse(j)
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.Font.Bold = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=" - "
Next i
Application.ScreenUpdating = True
End If
j = j + 1
Loop
End Sub
Any ideas?