Consulting

Results 1 to 1 of 1

Thread: Solved: Questions About VBA Created Tables

  1. #1
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location

    Solved: Questions About VBA Created Tables

    1. I am creating a table using VBA. I wish to horizontally center the text in a given cell. After poking around in the object browser and recording a macro for information purposes, it appears that this is achieved using the ParagraphFormat property of the cell's Range. For example:

    Selection.Tables(1).Cell(Row:=2, Column:=1).Range.ParagraphFormat = wdAlignParagraphCenter

    This statement generates a "Type Mismatch" compiler error.

    So, clearly there is something wrong. What should I be doing?

    2. I wish the first two rows in the table to be the "Header" and be repeated at the top of each page. It is pretty clear how to make one row the header, but how do I make two rows the header?


    3. After the table is created (2 cols wide by N row long), I adjust the col widths to what I want, merge the cells in the first row and add text and formatting to row 1 and row 2

    [VBA]
    With Selection.Tables(1)
    .Columns(1).PreferredWidthType = wdPreferredWidthPoints
    .Columns(1).PreferredWidth = InchesToPoints(1.7)
    .Columns(2).PreferredWidthType = wdPreferredWidthPoints
    .Columns(2).PreferredWidth = InchesToPoints(6.7)
    .cell(Row:=1, Column:=1).Merge MergeTo:=.cell(Row:=1, Column:=2)
    .Rows(1).Range = "Table of Stuff"
    .Rows(1).Range.Font.Size = 12
    .Rows(1).Range.Bold = True
    .Rows(1).Alignment = wdAlignRowCenter
    .cell(Row:=2, Column:=1).Range = "AAAA"
    .cell(Row:=2, Column:=1).Range.Bold = True
    .cell(Row:=2, Column:=2).Range = "BBBB"
    .cell(Row:=2, Column:=2).Range.Bold = True
    .Rows(1).HeadingFormat = True
    End With
    [/VBA]

    The results are not quite what I want:
    1. col 2 ends up being about 3.5 inches wide
    2. the first row is offset from the rest of the table about 1.5" to the right
    Any suggestions?

    Thanks
    Last edited by MWE; 02-14-2006 at 11:09 PM.
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

Posting Permissions

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