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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now