How to adjust table font in VB

C

chemicals

I have the following code which creates and populates a table in Word. I
want to set the fonts in the entire table to a smaller size and possibly a
different font type.
I am inserting this table at a bookmark. How can I do this for the entire
table?

Here's the code:
Dim objTable As Word.Table
Dim rngRange As Word.Range

If (m_objDoc.Bookmarks.Exists(strbkmk)) Then
Set rngRange = m_objDoc.Bookmarks(strbkmk).Range
m_objDoc.Bookmarks(strbkmk).Select
rngRange.Text = varText
rngRange.Select
Set objTable = m_objWord.Selection.ConvertToTable(Separator:=vbTab)
objTable.AutoFormat Format:=wdTableFormatGrid8, ApplyShading:=True,
ApplyBorders:=True, ApplyHeadingRows:=True
objTable.AutoFitBehavior wdAutoFitContent
Set objTable = Nothing
rngRange.SetRange Start:=rngRange.Start - 3, End:=rngRange.End + 3
'Debug.Print rngRange.Text
m_objDoc.Bookmarks.Add strbkmk
InsertTableAtBookmark = True
Else
MsgBox "Missing bookmark in Word template [" & strbkmk & "]"
InsertTableAtBookmark = False
End If
 
L

Lene Fredborg

If you insert the following code after the creation of your table, it will
change the font to Arial and the font size to 8 pt of all text in your table:

With objTable.Range.Font
.Name = "Arial"
.Size = 8
End With

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
K

Klaus Linke

Lene Fredborg said:
If you insert the following code after the creation of your table, it will
change the font to Arial and the font size to 8 pt of all text in your
table:

With objTable.Range.Font
.Name = "Arial"
.Size = 8
End With


You could also modify the table style (Table Grid 8 in your case)... which
might be a cleaner solution.
It only works if you haven't customized your Normal paragraph style though
(from its factory settings "Times New Roman 10 pt...").

With objTable.Style.Font
.Name = "Arial"
.Size = 8
' ...
End With

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top