fboehlandt
05-06-2013, 07:31 AM
Hello,
I am trying to replace the cell contents in a Word table. The exemplary code is given below:
Sub MyAccent()
Dim oCell As Word.Cell
With Selection
' \\ Check if selection is in a table
If .Information(wdWithInTable) Then
For Each oCell In .Tables(1).Range.Cells
If Trim(oCell.Range.Text) Like "*sss*" Then
oCell.Range.Text = Left(oCell.Range.Text, Len(oCell.Range.Text) - 5)
oCell.Range.Select
Selection.OMaths.Add Range:=Selection.Range
oCell.Range.Select
Selection.OMaths(1).Functions.Add(Selection.Range, wdOMathFunctionAcc).Acc _
.Char = 8411
ElseIf Trim(oCell.Range.Text) Like "*ss*" Then
oCell.Range.Text = Left(oCell.Range.Text, Len(oCell.Range.Text) - 4) '!<--
oCell.Range.Select
Selection.OMaths.Add Range:=Selection.Range
oCell.Range.Select
Selection.OMaths(1).Functions.Add(Selection.Range, wdOMathFunctionAcc).Acc _
.Char = 776
ElseIf Trim(oCell.Range.Text) Like "*s*" Then
oCell.Range.Text = Left(oCell.Range.Text, Len(oCell.Range.Text) - 3)
oCell.Range.Select
Selection.OMaths.Add Range:=Selection.Range
oCell.Range.Select
Selection.OMaths(1).Functions.Add(Selection.Range, wdOMathFunctionAcc).Acc _
.Char = 775
Else
oCell.Range.Select
Selection.OMaths.Add Range:=Selection.Range
End If
Next
End If
End With
End Sub
The moment the code gets to the marked line I receive the 'The range cannot be deleted error'. The first cell actually does change but that change must invoke the error later on. Can anyone help please?
I am trying to replace the cell contents in a Word table. The exemplary code is given below:
Sub MyAccent()
Dim oCell As Word.Cell
With Selection
' \\ Check if selection is in a table
If .Information(wdWithInTable) Then
For Each oCell In .Tables(1).Range.Cells
If Trim(oCell.Range.Text) Like "*sss*" Then
oCell.Range.Text = Left(oCell.Range.Text, Len(oCell.Range.Text) - 5)
oCell.Range.Select
Selection.OMaths.Add Range:=Selection.Range
oCell.Range.Select
Selection.OMaths(1).Functions.Add(Selection.Range, wdOMathFunctionAcc).Acc _
.Char = 8411
ElseIf Trim(oCell.Range.Text) Like "*ss*" Then
oCell.Range.Text = Left(oCell.Range.Text, Len(oCell.Range.Text) - 4) '!<--
oCell.Range.Select
Selection.OMaths.Add Range:=Selection.Range
oCell.Range.Select
Selection.OMaths(1).Functions.Add(Selection.Range, wdOMathFunctionAcc).Acc _
.Char = 776
ElseIf Trim(oCell.Range.Text) Like "*s*" Then
oCell.Range.Text = Left(oCell.Range.Text, Len(oCell.Range.Text) - 3)
oCell.Range.Select
Selection.OMaths.Add Range:=Selection.Range
oCell.Range.Select
Selection.OMaths(1).Functions.Add(Selection.Range, wdOMathFunctionAcc).Acc _
.Char = 775
Else
oCell.Range.Select
Selection.OMaths.Add Range:=Selection.Range
End If
Next
End If
End With
End Sub
The moment the code gets to the marked line I receive the 'The range cannot be deleted error'. The first cell actually does change but that change must invoke the error later on. Can anyone help please?