#1
|
|||
|
|||
Add text at beginning of cells in Word table
How can I add a text string at the beginning of each of the lefthand cells in a table?
Lets say the cell contains "1:2" I wish to add "Gen. " so that it reads "Gen. 1:2" The start of every lefthand cell must be set to "Gen. " |
#2
|
|||
|
|||
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oTbl As Table Dim oCell As Cell Set oTbl = Selection.Tables(1) For Each oCell In oTbl.Range.Cells If oCell.ColumnIndex = 1 Then If Len(oCell.Range.Text) > 2 Then oCell.Range.InsertBefore "Gen " End If End If Next lbl_Exit: Exit Sub End Sub Sub ScratchMacro2() 'A basic Word macro coded by Greg Maxey Dim oTbl As Table Dim oCol As Column Dim oCell As Cell Set oTbl = Selection.Tables(1) If oTbl.Uniform Then Set oCol = oTbl.Columns(1) For Each oCell In oCol.Cells If oCell.ColumnIndex = 1 Then If Len(oCell.Range.Text) > 2 Then oCell.Range.InsertBefore "Gen " End If End If Next End If lbl_Exit: Exit Sub End Sub If the table is uniform, the second macro will be faster. |
#3
|
|||
|
|||
Thank you!
|
Tags |
cell, table, word 365 |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Converting table to text (and back) with carriage returns in cells, split and merged cells | ndajko | Word | 5 | 11-04-2019 07:53 AM |
Word macro to insert text at the beginning of paragraph but skip tables | ashalles135 | Word VBA | 5 | 09-26-2018 09:49 AM |
word macro To insert text at the beginning and at end of paragraph | ArieH | Word VBA | 20 | 09-10-2017 04:23 PM |
Text position in merged table cells - word 2010 | ellentk | Word Tables | 3 | 09-09-2015 03:33 PM |
Add text to the beginning/ending of each line in word | ballmoney | Word | 1 | 01-17-2010 02:19 AM |