Solved

Macro in MS Publisher 2010 that will insert 2 rows in a table without adding to the height of the table

Posted on 2011-09-15
2
304 Views
Last Modified: 2012-08-13
I'm new to Publisher and I find that it's almost impossible to control the dimensions and behavior of tables without macros, and I haven't had much luck finding macros online. I did find one to create tables, but I can't find anything on how to modify them.

Right now, I would like something that enables me to:

insert one or two rows into my newly created table while maintaining its height at 540 px.
merge the 3 rows in Columns 1 and 3 into one cell, while leaving three rows in Column 2 with a value of x in Row 1, y in Row 2, and z in Row 3. Sample values might be Row 1 of Column 2 = 100, Row 2 = 160, Row 3 = 280

Also, please let me know where I can find an online source for other macros such as adding a border, or fill color or background image to a given cell and/or the entire table.

Thanks,
John

I couldn't find a Publisher zone. Is there one?
Sub TriFold()
    With ActiveDocument.Pages(1).Shapes.AddTable(NumRows:=1, NumColumns:=5, Left:=36, Top:=36, Width:=792, Height:=3540).Table
            .Rows(1).Height = 540
            .Columns(1).Width = 224
            .Columns(2).Width = 24
            .Columns(3).Width = 224
            .Columns(4).Width = 24
            .Columns(5).Width = 224
    End With
End Sub

Open in new window

0
Comment
Question by:gabrielPennyback
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 36558529
The Publisher object model appears to be very similar to that of Word, so I was able to come up with this.
Option Explicit

Sub TriFold()
    Dim tbl As Table
    Dim rw As Row
    
    Dim TableHeight As Single
    TableHeight = 540
    
    'ActiveDocument.Pages(1).Shapes(1).Delete
    Set tbl = ActiveDocument.Pages(1).Shapes.AddTable(NumRows:=1, NumColumns:=5, Left:=36, Top:=36, Width:=792, Height:=TableHeight).Table
         With tbl
            .Columns(1).Width = 224
            .Columns(2).Width = 24
            .Columns(3).Width = 224
            .Columns(4).Width = 24
            .Columns(5).Width = 224
    End With
    'add more rows
    Set rw = tbl.Rows.Add
    Set rw = tbl.Rows.Add
    'adjust height of rows
    For Each rw In tbl.Rows
        rw.Height = TableHeight / tbl.Rows.Count
    Next rw
    'merge cells in column 1
    tbl.Rows(1).Cells(1).Merge tbl.Rows(2).Cells(1)
    tbl.Rows(1).Cells(1).Merge tbl.Rows(3).Cells(1)
    'put some text in a cell
    tbl.Rows(1).Cells(2).TextRange.Text = 100
End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:gabrielPennyback
ID: 36913554
Thanks, GrahamSkan. Sorry I lost track of this question.

- John
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question