vba powerpoint file generation take large amount of time

R

Rene Mouchot

Hello all,
I'd like to optimize a vba program that generate a powerpoint file with at
least 80 slides ( with one table per slide).
The process is : create new powerpoint file, [add new slide, fill the slide
with data] *, save and close the powerpoint file.
Actually it take10-15 minutes to do the work, so i'd like to know if there
are general tricks to speed up a powerpoint file generation ?

Thanks,
 
S

Steve Rindsberg

Hello all,
I'd like to optimize a vba program that generate a powerpoint file with at
least 80 slides ( with one table per slide).
The process is : create new powerpoint file, [add new slide, fill the slide
with data] *, save and close the powerpoint file.
Actually it take10-15 minutes to do the work, so i'd like to know if there
are general tricks to speed up a powerpoint file generation ?

Never select anything if you can avoid it. That alone can speed code up by a
factor of 100 or so.

W/o seeing example code, it's hard to say more.
 
S

Shyam Pillai

Rene,
What Steve said and also lock the screen updates. Even better if you can run
the automation by keeping the application invisible.
Besides this, we need for code optimization you need to post some code.

Regards,
Shyam Pillai

http://skp.mvps.org/
 
B

Brian Reilly, MS MVP

In addition to Steve and Shyam's excellent suggestions, I think you'd
speed things up by using Excel rather than PPT's tables features.

Brian Reilly, PowerPoint MVP
 
R

Rene Mouchot

Shyam Pillai said:
Rene Mouchot said:
Hello all,
I'd like to optimize a vba program that generate a powerpoint file with at
least 80 slides ( with one table per slide).
The process is : create new powerpoint file, [add new slide, fill the
slide
with data] *, save and close the powerpoint file.
Actually it take10-15 minutes to do the work, so i'd like to know if there
are general tricks to speed up a powerpoint file generation ?

Thanks,

Rene,
What Steve said and also lock the screen updates. Even better if you can run
the automation by keeping the application invisible.
Besides this, we need for code optimization you need to post some code.

Regards,
Shyam Pillai

http://skp.mvps.org/

Steven, Shyam,
Sorry for the high response time :blush:)

In the script i do a lot of call to InsertAfter function, then i set font
properties.

I can't really paste a vb code snippet cause i use perl to automate
powerpoint, but i'll try to translate and then you could maybe see what are
the functions call that cause problem.
Please take cate that the following code could not be correct.

For example i create a table of fixed width in each slide and i write in the
rows by calling InsertAfter in a TextRange. I set then some font properties
:

Set oTextRange = pptShape.Table.cell(intRowIndex,
1).Shape.TextFrame.TextRange.InsertAfter("Some text)
oTextRange.Font.Bold = True
oTextRange.Font.Name = "Arial"
oTextRange.Font.Size = 10
Set oTextRange = pptShape.Table.cell(intRowIndex,
2).Shape.TextFrame.TextRange.InsertAfter("Some another text)
oTextRange.Font.Name = "Arial"
oTextRange.Font.Size = 10
oTextRange.Font.Underline = True
etc...

When a table is totally filled, i set the width with fixed size and i hide
some borders:

For a row :

' set table border of one cell
set row = oTable.Table.Rows.Item(1)
row.Cells.Borders.Item(1).Visible = -1 ' ppBorderTop
row.Cells.Borders.Item(2).Visible = 0 ' ppBorderLeft
row.Cells.Borders.Item(3).Visible = 0 ' ppBorderBottom
row.Cells.Borders.Item(4).Visible = 0 ' ppBorderRight
' set table width
oTable.Table.Columns.Item(1).Width = 150
oTable.Table.Columns.Item(2).Width = 130
oTable.Table.Columns.Item(3).Width = 35
oTable.Table.Columns.Item(4).Width = 80
oTable.Table.Columns.Item(5).Width = 80
oTable.Table.Columns.Item(6).Width = 80
oTable.Table.Columns.Item(7).Width = 80
oTable.Table.Columns.Item(8).Width = 80

I guess i could use another function instead of InsertAfter, cause it's
seems to cause the problem, maybe you have an idea ?

--
 
S

Steve Rindsberg

Set oTextRange = pptShape.Table.cell(intRowIndex,
1).Shape.TextFrame.TextRange.InsertAfter("Some text)

If InsertAfter seems to be slowing it down, try:

Set oTextRange = pptShape.Table.cell(intRowIndex, _
1).Shape.TextFrame.TextRange
oTextRange.Text = "Some text"
' or if you need to append to the existing text
' oTextRange.Text = oTextRange.Text & "Some text"
 
?

=?ISO-8859-1?Q?Ren=E9_Mouchot?=

Steve said:
If InsertAfter seems to be slowing it down, try:

Set oTextRange = pptShape.Table.cell(intRowIndex, _
1).Shape.TextFrame.TextRange
oTextRange.Text = "Some text"
' or if you need to append to the existing text
' oTextRange.Text = oTextRange.Text & "Some text"

ok thanks steve (and not steven sorry :blush:) ), i'll try that but what if
i'd like to set different font properties to the new text i append ?
Typically what i need is to write a text in bold followed by a text in
non-bold or underlined, etc... is that possible with that way ?
 
S

Steve Rindsberg

ok thanks steve (and not steven sorry :blush:) ), i'll try that but what if
i'd like to set different font properties to the new text i append ?
Typically what i need is to write a text in bold followed by a text in
non-bold or underlined, etc... is that possible with that way ?

You'd need to do some tests to see which is quicker, but you could pick up the
length of the text first, append your new text, then use .Characters to set a
subrange of text to which you'd apply your formatting.
 
R

Rene Mouchot

Steve Rindsberg said:
You'd need to do some tests to see which is quicker, but you could pick up the
length of the text first, append your new text, then use .Characters to set a
subrange of text to which you'd apply your formatting.

Finally i decided to use .<code>TextRange.Text = "Some text"</code> and
remove completly all formatting on the document, except that i set at the
beginning the default font to the one i desired ( size is smaller than the
default) by using call to
Presentation.SlideMaster.TextStyles(...).Levels(..).Font.Size = 10 for all
TextStyles and all Levels (!). This increased greatly the execution time and
i have now a useable script, even for 80 or more generated slides. You were
right about the selection, it's time consuming, thanks for you help!
If i have time in the futur, i will check if the use of .Characters is
valuable.
 
S

Steve Rindsberg

I'm glad to hear that this is working well for you. Thanks for letting us
know!
 

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