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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

708 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

12 Experts available now in Live!

Get 1:1 Help Now