![]() |
#1
|
|||
|
|||
![]()
Hi all,
i am completely new to macro's i have large documents which are text only. in these documents i would like to search for "T." at the beginning of a sentence. and in case found, insert a table after the text like in the attached document. i would be verry greatfull if someone can help me out with the required macro code. thanks verry much in advance. |
#2
|
||||
|
||||
![]()
Probably something like
Code:
Sub Macro1() Dim oRng As Range Dim oTable As Table Dim oCell As Range Set oRng = ActiveDocument.Range With oRng.Find Do While .Execute(findText:="T. ") If oRng.Start = oRng.Paragraphs(1).Range.Start Then oRng.End = oRng.Paragraphs(1).Range.End oRng.Collapse 0 Set oTable = ActiveDocument.Tables.Add(oRng, 2, 3) With oTable .Columns(1).Width = CentimetersToPoints(1.17) .Columns(2).Width = CentimetersToPoints(1.47) .Columns(3).Width = CentimetersToPoints(13.35) Set oCell = .Cell(1, 1).Range oCell.End = oCell.End - 1 oCell.Text = "Date" Set oCell = .Cell(1, 2).Range oCell.End = oCell.End - 1 oCell.Text = "Initials" Set oCell = .Cell(1, 3).Range oCell.End = oCell.End - 1 oCell.Text = "Remarks" End With End If Loop End With Set oRng = Nothing Set oCell = Nothing Set oRng = Nothing End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]()
Thanks verry much Graham,
this code does the trick! which code do i need to show the lines of the table in black? thanks verry much in advance |
#4
|
||||
|
||||
![]()
Add the line
Code:
.Style = "Table Grid" Code:
With oTable
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
![]()
Thanks so much Graham for your support.
You really helped me out well. Only i have a dutch version of word, so i had to change "Table Grid" for "Tabelraster" otherwise the command is not recognised. now everything works completely fine. Many thanks again, i will set as solved. |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Auto insert of first line as file name on initial save | elof69 | Word | 3 | 05-08-2019 11:05 PM |
Auto insert table line | johngav | Word Tables | 3 | 07-13-2017 08:44 AM |
![]() |
pstein | Word | 12 | 10-29-2014 04:31 AM |
How to insert a diagonal line across multiple cells in a Table? | Joey Cheung | Word Tables | 1 | 10-10-2014 07:15 PM |
auto-detect display options? | davidt76 | PowerPoint | 0 | 09-30-2011 07:26 AM |