Thread: [Solved] Underline Inserted Text
View Single Post
 
Old 01-11-2017, 10:55 AM
jmltinc jmltinc is offline Windows 7 64bit Office 2016
Novice
 
Join Date: Jan 2017
Posts: 9
jmltinc is on a distinguished road
Default Underline Inserted Text

Hi Folks,

Another trip to the well for a Word VBA Newb...

I have VBA code which opens a Word instance and programmatically populates the document with tables. However, each table must have a title, so my code is:

Code:
        Selection.Text = " Product Specifications"
        Selection.Font.Name = "calibri"
        Selection.Font.Size = 16
        Selection.Font.Bold = True
        Selection.EndKey Unit:=wdStory
 'Now add table...
        .Tables.Add Range:=Selection.Range, NumRows:=3, NumColumns:=4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
Now, if I want the title underlined, the code becomes:
Code:
        Selection.Text = " Product Specifications"
        Selection.Font.Name = "calibri"
        Selection.Font.Size = 16
        Selection.Font.Bold = True
        Selection.Font.Underline = wdUnderlineSingle 
        Selection.EndKey Unit:=wdStory
 'Now add table...
        .Tables.Add Range:=Selection.Range, NumRows:=3, NumColumns:=4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
.

Of course, when I do, everything in the document after that line is underlined.

I only want the titles underlined. What am I doing wrong, please?

Thanks,
-John
Reply With Quote