4
votes

I have a table with two columns and "x" number of rows.

In the 2nd column is formatted text which I would like to change to unformatted text.

The manual way of doing so is:

Select the whole cell in the 2nd column » Cut » Click Edit » Click Paste Special » Click Unformatted

The idea is to paste the unformatted text back into the cell it was Cut from and then move down to the cell below.

I would really appreciate some code that can apply this to all the cells in the 2nd column of a table.

1
can you give sample of formatted and unformatted text? - user2140173
Let me fully explain. When I cut and paste special, I remove all formatting but keep line breaks and bullet marks. This is to allow me to import into Excel but maintain the structure of my paragraph - AneeshS
Have you tried recording a macro? - user2140173
Is there a way to speak to you more directly so I can explain it better? - AneeshS
Yes and for some reason I am unable to - AneeshS

1 Answers

2
votes

Here is the solution to my problem. A friend had a piece of code which I manipulated to suit my needs:

Sub CutAndPasteSpecialUnformatted()

        Dim value As Variable

        ' Process every row in the current table. '
        Dim row As Integer
        Dim rng As Range

        For row = 1 To Selection.Tables(1).Rows.Count
            ' Get the range for the rightmost cell. '
            Selection.Collapse Direction:=wdCollapseStart
            Set rng = Selection.Tables(1).Cell(row, Column:=2).Range

            ' For each, toggle text in rightmost cell. '
            rng.Select
            Selection.Copy
            Selection.Delete
            rng.Select
            Selection.Style = ActiveDocument.Styles("Normal")
            Selection.Delete
            Selection.Collapse Direction:=wdCollapseStart
            Selection.Range.PasteSpecial DataType:=wdPasteText
        Next

End Sub