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
300 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

740 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