R
Robert
Hello Everybody,
Would one of you experts kindly look over my coding and tell me why it
doesn't work.
In a Wd document I am trying to find (single) words, already formatted
with a blue background, and copy them into an existing table which is
already partly full. They will all be copied into Column 1, but we must
first find where the first empty cell is in the Column.
The Find routine tested OK and displayed the "BluWords" on the
document. But not after I had added coding to insert them in the Table.
At present, the routine finishes with Column 1 selected, but no
BluWords anywhere in evidence.
The line marked "Note 1" is needed because the While..Wend loop rotates
one time more than the number of BluWords found in the sample text.
It would be REALLY good if the macro could also pick up the blue
character formatting as well as the BluWord and transfer both into the
Table, but I ask too much.
Has anyone any ideas, please?
Many thanks,
Robert.
Dim myRng As Range
Dim BluWord As String
Dim counter As Integer
Dim oCell As Cell
counter = 0
Set myRng = ActiveDocument.Range
With myRng.Find
.Text = ""
.Format = True
.Font.Shading.BackgroundPatternColor = wdColorBlue
While .Execute
counter = counter + 1
BluWord = myRng.Text
'============================== PROBLEMS START HERE
If Len(BluWord) > 1 Then 'See Note 1.
ActiveDocument.Tables(1).Cell(1, 1).Select
Selection.Columns(1).Select
'The code below tests if each Cell is empty & if so, writes BluWord
For Each oCell In Selection.Cells
If Len(oCell.Range.Text) < 2 Then
Selection.TypeText BluWord
End If
Next oCell
End If
Wend
End With
End Sub
Would one of you experts kindly look over my coding and tell me why it
doesn't work.
In a Wd document I am trying to find (single) words, already formatted
with a blue background, and copy them into an existing table which is
already partly full. They will all be copied into Column 1, but we must
first find where the first empty cell is in the Column.
The Find routine tested OK and displayed the "BluWords" on the
document. But not after I had added coding to insert them in the Table.
At present, the routine finishes with Column 1 selected, but no
BluWords anywhere in evidence.
The line marked "Note 1" is needed because the While..Wend loop rotates
one time more than the number of BluWords found in the sample text.
It would be REALLY good if the macro could also pick up the blue
character formatting as well as the BluWord and transfer both into the
Table, but I ask too much.
Has anyone any ideas, please?
Many thanks,
Robert.
Dim myRng As Range
Dim BluWord As String
Dim counter As Integer
Dim oCell As Cell
counter = 0
Set myRng = ActiveDocument.Range
With myRng.Find
.Text = ""
.Format = True
.Font.Shading.BackgroundPatternColor = wdColorBlue
While .Execute
counter = counter + 1
BluWord = myRng.Text
'============================== PROBLEMS START HERE
If Len(BluWord) > 1 Then 'See Note 1.
ActiveDocument.Tables(1).Cell(1, 1).Select
Selection.Columns(1).Select
'The code below tests if each Cell is empty & if so, writes BluWord
For Each oCell In Selection.Cells
If Len(oCell.Range.Text) < 2 Then
Selection.TypeText BluWord
End If
Next oCell
End If
Wend
End With
End Sub