vertical spacing in tables with Powerpoint Automation

M

mstuehler

All,

I'm having the following problem:

I'm using vba/vbscript to automate a Powerpoint 2003 document. One of my
slides has a powerpoint "table", and I use vba/vbscript to load text into the
table cells.

If I use Powerpoint in visible mode:

Dim oApp
Set oApp = CreateObject("Powerpoint.Application")
oApp.Visible = True
Dim oPres
Set oPres = oApp.Presentations.Open("test.ppt")

Then Powerpoint automatically readjusts the height of the cells to fit the
content. However, if I use Powerpoint in "hidden" mode:

Dim oApp
Set oApp = CreateObject("Powerpoint.Application")
Dim oPres
Set oPres = oApp.Presentations.Open("test.ppt",,,false)

Then Powerpoint doesn't readjust the cell height to fit the content, and the
rows "run over" each other.

Is there a way to correct this? For example, some method that tells the rows
to re-adjust the height to fit the content?

Many thanks in advance!

Cheers,
Matt Stuehler
 
S

Shyam Pillai

Hello Matt,
Merely stating the effect is of little use, I'd suggest that you post the
relevant code snippet so that we can try to understand the cause and suggest
a solution.
 
M

mstuehler

Shyam,

My apologies for the poor post.

Here's the complete code snippet:

Dim oApp
Set oApp = CreateObject("Powerpoint.Application")
oApp.Visible = True
Dim oPres
Set oPres = oApp.Presentations.Open("test.ppt")
Dim oSlide
Set oSlide = oPres.Slides("slideWithTable")
Dim oShape
oShape = oSlide.Shapes("table")
With (oShape.Table)
.Cell(1, 1).Shape.TextFrame.TextRange.Text = "Some content..."
.Cell(2, 1).Shape.TextFrame.TextRange.Text = "Some more content..."
.Cell(3, 1).Shape.TextFrame.TextRange.Text = "Rest of content..."
End With

Now, if I run that code, the content is placed into the cells appropriately.
More importantly, Powerpoint automatically increases the height of those
cells/rows to fit the content - in other words, if the content wraps to
several lines, Powerpoint makes the cell/row tall enough to fit it.

However, if I try to run powerpoint in "hidden" mode by changing these lines:

Dim oApp
Set oApp = CreateObject("Powerpoint.Application")
Dim oPres
Set oPres = oApp.Presentations.Open("test.ppt",,,false)

Then Powerpoint DOESN'T adjust the height of those cells/rows automatically,
and the table layout gets messed up. Strangely, if you later go in to the
..ppt MANUALLY, and edit the content, then Powerpoint DOES readjust the
row/cell height properly. It only seems not to work when Powerpoint is not
visible.

Thanks again for all your time and help!

Cheers,
Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top