In Word 2003 how to insert characters before all cell markers

M

MathKing

I want to insert a character before the cell marker in many cells in a table.
I can't use the find and replace feature. There must be a way to do this (or
to delete a character before every cell marker). Can someone help me?
 
M

macropod

Hi MathKing,

You could add text to the end of each selected cell via a macro like:
Sub AddDemo()
Dim oCel As Cell, StrTxt As String
StrTxt = InputBox("What is the text to insert at the end of each selected cell")
For Each oCel In Selection.Cells
oCel.Range.InsertAfter (StrTxt)
Next
End Sub

Similarly, you can delete the last character with:
Sub DelDemo()
Dim oCel As Cell, lStr As Long
For Each oCel In Selection.Cells
lStr = oCel.Range.Characters.Count
If lStr > 1 Then oCel.Range.Characters(lStr - 1).Delete
Next
End Sub
 
D

DeanH

Hi Macropod.
Again a very nice little macro set.
Question though, how can the first macro be changed to deal with any and all
tables within a document not just selected cells, and also have the text to
be inserted preset?
Many thanks
DeanH

macropod said:
Hi MathKing,

You could add text to the end of each selected cell via a macro like:
Sub AddDemo()
Dim oCel As Cell, StrTxt As String
StrTxt = InputBox("What is the text to insert at the end of each selected cell")
For Each oCel In Selection.Cells
oCel.Range.InsertAfter (StrTxt)
Next
End Sub

Similarly, you can delete the last character with:
Sub DelDemo()
Dim oCel As Cell, lStr As Long
For Each oCel In Selection.Cells
lStr = oCel.Range.Characters.Count
If lStr > 1 Then oCel.Range.Characters(lStr - 1).Delete
Next
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


MathKing said:
I want to insert a character before the cell marker in many cells in a table.
I can't use the find and replace feature. There must be a way to do this (or
to delete a character before every cell marker). Can someone help me?
 
M

macropod

Hi Dean,

You could use something like:
Sub AddAllDemo()
Dim oTbl As Table, oCel As Cell, StrTxt As String
StrTxt = "MyText"
For Each oTbl In ActiveDocument.Tables
For Each oCel In oTbl.Cells
oCel.Range.InsertAfter (StrTxt)
Next
Next
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


DeanH said:
Hi Macropod.
Again a very nice little macro set.
Question though, how can the first macro be changed to deal with any and all
tables within a document not just selected cells, and also have the text to
be inserted preset?
Many thanks
DeanH

macropod said:
Hi MathKing,

You could add text to the end of each selected cell via a macro like:
Sub AddDemo()
Dim oCel As Cell, StrTxt As String
StrTxt = InputBox("What is the text to insert at the end of each selected cell")
For Each oCel In Selection.Cells
oCel.Range.InsertAfter (StrTxt)
Next
End Sub

Similarly, you can delete the last character with:
Sub DelDemo()
Dim oCel As Cell, lStr As Long
For Each oCel In Selection.Cells
lStr = oCel.Range.Characters.Count
If lStr > 1 Then oCel.Range.Characters(lStr - 1).Delete
Next
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


MathKing said:
I want to insert a character before the cell marker in many cells in a table.
I can't use the find and replace feature. There must be a way to do this (or
to delete a character before every cell marker). Can someone help me?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top