PDA

View Full Version : [SOLVED:] Table to be font size



RayKay
01-17-2019, 04:15 AM
Hi John

I'm hoping you, or anyone, can help me with the blue code below.
The VBA puts borders between table rows that are selected.

The aim was for fonts to become Arial Size 12 - but it only updates text and not bulleted text.
Is it possible to change bulleted text too?

Thank you.



Public Sub TableDividerLines()


Dim tbl As Table
Dim iCol As Integer
Dim iRow As Integer
Dim I As Integer
On Error GoTo err
Set tbl = ActiveWindow.Selection.ShapeRange(1).Table
' hide selected borders
Call CommandBars.ExecuteMso("BorderNone")
DoEvents
'exit if no selected table
If err.Number <> 0 Then Exit Sub
For iRow = 1 To tbl.Rows.Count
For iCol = 1 To tbl.Columns.Count
If tbl.Cell(iRow, iCol).Selected Then
For I = 1 To 3 Step 2
With tbl.Cell(iRow, iCol).Borders(I)
.visible = msoTrue
.ForeColor.RGB = RGB(180, 180, 180)
.Weight = 0.75


Dim oShp As Shape
Dim oTbl As Table
Dim K As Long
Dim J As Long
Set oShp = ActiveWindow.Selection.ShapeRange(1)
Set oTbl = oShp.Table
For K = 1 To oTbl.Columns.Count
For J = 1 To oTbl.Rows.Count
oTbl.Cell(I, J).Shape.TextFrame.TextRange.Font.Name = "Arial"
oTbl.Cell(I, J).Shape.TextFrame.TextRange.Font.Size = 12
Next
Next


End With
Next I
End If
Next iCol
Next iRow
Exit Sub ' usual exit
err: 'error
MsgBox "Please select table rows / cells and try again"
End Sub

John Wilson
01-17-2019, 07:06 AM
You have the outer (Rows) loop and the inner loop the wrong way around.


Dim oShp As Shape
Dim oTbl As Table
Dim R As Integer
Dim C As Integer
Set oShp = ActiveWindow.Selection.ShapeRange(1)
Set oTbl = oShp.Table
For R = 1 To oTbl.Rows.Count ' outer loop is Rows
For C = 1 To oTbl.Columns.Count 'Inner is Columns
oTbl.Cell(R, C).Shape.TextFrame.TextRange.Font.Name = "Arial"
oTbl.Cell(R, C).Shape.TextFrame.TextRange.Font.Size = 12
Next
Next

RayKay
01-17-2019, 07:18 AM
Thanks John. You're the most intelligent person I've ever crossed paths with.
Thank you!

John Wilson
01-17-2019, 07:24 AM
You haven't met my wife then!