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
292 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
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i reset all images size to default in a word file 6 69
stop word moving down 2 62
Regarding Notepad++ 4 43
microsoft word short cuts 3 35
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

778 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