Thread: [Solved] Underline Inserted Text
View Single Post
 
Old 01-23-2017, 02:13 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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 ofgmayor has much to be proud of
Default

TypeParagraph will insert a paragraph break. You don't need an extra one. There will be one at the end of the paragraph before your table. If you want more space add it to the paragraph.

It is better to set ranges and work with ranges and name the tables if you wish to process them e.g.

Code:
Dim oRng As Range
Dim oTable As Table
    Set oRng = Selection.Range
    With oRng
        'Product Specifications
        .Text = " Product Specifications"
        .Font.Name = "Calibri"
        .Font.Size = 16
        .Font.Bold = True
        .Collapse 0    'collapse the range to its end
        'Insert a table at the range
        Set oTable = .Tables.Add(Range:=oRng, NumRows:=3, _
                                 NumColumns:=4, _
                                 DefaultTableBehavior:=wdWord9TableBehavior, _
                                 AutoFitBehavior:=wdAutoFitFixed)
        .End = oTable.Range.End + 1    'set the end of the range to just beyond the table
        'do stuff with otable
        .Collapse 0    'collapse the range to its end
        'Add another heading
        .Text = " Another heading"
        .Font.Name = "Calibri"
        .Font.Size = 16
        .Font.Bold = True
        .Collapse 0    'collapse the range to its end
        'Insert a table at the range
        Set oTable = .Tables.Add(Range:=oRng, NumRows:=3, _
                                 NumColumns:=4, _
                                 DefaultTableBehavior:=wdWord9TableBehavior, _
                                 AutoFitBehavior:=wdAutoFitFixed)
        .End = oTable.Range.End + 1    'set the end of the range to just beyond the table
        'do stuff with otable
        .Collapse 0    'collapse the range to its end
        .Select    'moves the cursor to the end of the table
    End With
__________________
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