Consulting

Results 1 to 2 of 2

Thread: Having trouble formatting my table with VBA

  1. #1
    VBAX Newbie
    Joined
    Sep 2018
    Posts
    3
    Location

    Having trouble formatting my table with VBA

    Hello,

    I am creating a table in VBA and have a number of formatting requirements. I am having trouble with 2 formatting specifics:

    1. Adding a bottom border to the top row only
    2. Adjusting the height and width of the cells within the table. I want the top row to have a height of 0.2", the remaining 16 rows to have a height of 0.25", the first column to have a width of 1.51" and the second column to have a width of 0.75"

    I have only included the relevant portions of the code that I am having trouble with. Currently when I run the code, there is no border created, and the cell height / width is not set.

    Thanks in advance for your help I really appreciate it!

    ' Create table
    Dim tbl As Shape
    Dim lRow As Long
    Dim lColumn As Long


    Set tbl = Sld.Shapes.AddTable(17, 2)
    With tbl.Table


    ' Initially formats the table as no style, no grid so that it can be adjusted
    .ApplyStyle "{2D5ABB26-0587-4C30-8999-92F81FD0307C},True"

    'Text & border for the top row
    With .Cell(1, 1)
    .Shape.TextFrame.TextRange.Text = "Header 1"
    .Shape.TextFrame.TextRange.Font.Color.RGB = RGB(90, 90, 90)
    .Shape.TextFrame.TextRange.Font.Name = "Arial"
    .Shape.TextFrame.TextRange.Font.Size = 10
    .Borders(ppBorderBottom).ForeColor.RGB = RGB(90, 90, 90)
    End With

    With .Cell(1, 2)
    .Shape.TextFrame.TextRange.Text = "Header 2"
    .Shape.TextFrame.TextRange.Font.Color.RGB = RGB(90, 90, 90)
    .Shape.TextFrame.TextRange.Font.Name = "Arial"
    .Shape.TextFrame.TextRange.Font.Size = 10
    .Borders(ppBorderBottom).ForeColor.RGB = RGB(90, 90, 90)
    End With

    ' Height of Rows and Width of Columns
    With .Columns(1)
    .Width = 108.72
    .Height = 18
    End With


    With .Columns(2)
    .Width = 54
    .Height = 18
    End With


    With .Rows(1)
    .Height = 14.4
    End With

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Columns cannot have a height

    Before setting the bottom border color set the .visible property to True
    Last edited by John Wilson; 10-03-2018 at 12:48 PM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •