0tto
05-04-2010, 01:58 AM
Hello everyone,
I'm having some problems getting a search and replace function going. What I want to achieve is a function that replaces all occurrences of a text within a table cell (that I have already selected) except if the text is part of a bulleted list.
This is what I have come up with so far:
Public Sub Replace2()
Dim rDcm As Range
' Set rDcm = ActiveDocument.Range
Set rDcm = Selection.Range
With rDcm.Find
.Text = "long"
Do While .Execute
If rDcm.ListFormat.ListType <> wdListBullet Then
rDcm.Text = "short"
' rDcm.Collapse wdCollapseEnd
End If
Loop
End With
End Sub
The problem with this one is that it only replaces the first instance of the word in the cell, even though it's inside the while execute loop. :think:
I've also tried another approach but this changes the selection so it will also replace instances outside of the selected cell.
Public Sub Replace4()
With Selection.Find
.Text = "long"
Do While .Execute
If Selection.Range.ListFormat.ListType <> wdListBullet Then
Selection.Range.Text = "short"
' Chr(11)
' Chr (13) + Chr(10)
' rDcm.Collapse wdCollapseEnd
End If
Loop
End With
End Sub
Any suggestions would be very welcome.
I'm having some problems getting a search and replace function going. What I want to achieve is a function that replaces all occurrences of a text within a table cell (that I have already selected) except if the text is part of a bulleted list.
This is what I have come up with so far:
Public Sub Replace2()
Dim rDcm As Range
' Set rDcm = ActiveDocument.Range
Set rDcm = Selection.Range
With rDcm.Find
.Text = "long"
Do While .Execute
If rDcm.ListFormat.ListType <> wdListBullet Then
rDcm.Text = "short"
' rDcm.Collapse wdCollapseEnd
End If
Loop
End With
End Sub
The problem with this one is that it only replaces the first instance of the word in the cell, even though it's inside the while execute loop. :think:
I've also tried another approach but this changes the selection so it will also replace instances outside of the selected cell.
Public Sub Replace4()
With Selection.Find
.Text = "long"
Do While .Execute
If Selection.Range.ListFormat.ListType <> wdListBullet Then
Selection.Range.Text = "short"
' Chr(11)
' Chr (13) + Chr(10)
' rDcm.Collapse wdCollapseEnd
End If
Loop
End With
End Sub
Any suggestions would be very welcome.