Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-23-2019, 06:24 AM
Rogireus Rogireus is offline vba detect first char in line and auto insert table Windows 7 64bit vba detect first char in line and auto insert table Office 2013
Novice
vba detect first char in line and auto insert table
 
Join Date: Oct 2019
Location: Netherlands
Posts: 3
Rogireus is on a distinguished road
Default vba detect first char in line and auto insert table

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.
Attached Files
File Type: docx macroTestdocument.docx (12.1 KB, 8 views)
Reply With Quote
  #2  
Old 10-24-2019, 01:58 AM
gmayor's Avatar
gmayor gmayor is offline vba detect first char in line and auto insert table Windows 10 vba detect first char in line and auto insert table Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 10-24-2019, 04:08 AM
Rogireus Rogireus is offline vba detect first char in line and auto insert table Windows 7 64bit vba detect first char in line and auto insert table Office 2013
Novice
vba detect first char in line and auto insert table
 
Join Date: Oct 2019
Location: Netherlands
Posts: 3
Rogireus is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 10-24-2019, 04:26 AM
gmayor's Avatar
gmayor gmayor is offline vba detect first char in line and auto insert table Windows 10 vba detect first char in line and auto insert table Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Add the line
Code:
.Style = "Table Grid"
immediately after the line
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
Reply With Quote
  #5  
Old 10-24-2019, 05:25 AM
Rogireus Rogireus is offline vba detect first char in line and auto insert table Windows 7 64bit vba detect first char in line and auto insert table Office 2013
Novice
vba detect first char in line and auto insert table
 
Join Date: Oct 2019
Location: Netherlands
Posts: 3
Rogireus is on a distinguished road
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
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
vba detect first char in line and auto insert table How to insert a line BEFORE a table in Word2007? 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:02 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft