Adding Text to Slides Programmatically

J

Jimmy

I am currently within an MS Office application and I have calculated
many text items assigned to string variables in VBA.

What I want to do is wake up PowerPoint and place these text items as
bullets on a slide. I also want to be able to specify the slide title block.

Here is what I have so far. It wakes up PPT and makes a slide for me. Now,
I want to add text to this new slide:

Public Sub MakeSlide() 'from VBA window
Dim ppt As Object
Dim pptPres As Presentation
Dim pptSlide As Slide
Set ppt = New PowerPoint.Application
Set pptPres = ppt.Presentations.Add(True)
pptPres.Slides.Add 1, ppLayoutText 'Adds slide #1
Set pptSlide = pptPres.Slides.Item(1)
With pptslide
'What goes here????
' I need a title for my slide, let's call it myTitle
'I need to add bullets: Bullet1, Bullet2, Bullet3, etc.
End With

ppt.Visible = True
End Sub

Thank you in advance for you assistance.
 
D

David M. Marcovitz

I do something very similar to this in Example 7.8 on my site
(http://www.PowerfulPowerPoint.com). I don't access the PowerPoint
externally; I do that from within the PowerPoint, but once you have a
slide object, it is basically the same. Note that in the slide, Shape(1)
is the title, and Shape(2) is the bulleted text area. We can be
completely confident of this because you just added the slide yourself
(if you were working from an existing slide, you would need all kinds of
error-checking to make sure it had a title area and a text area).

pptSlide.Shapes(1).TextFrame.TextRange.Text = _
"Your Title"
pptSlide.Shapes(2).TextFrame.TextRange.Text = _
"Your First Bullet Point" & Chr$(13) & _
"Your Second Bullet Point" & Chr$(13) & _
"Your Third Bullet Point & Chr$(13)


--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
J

Jimmy

Thank you. Your link was also most helpful.
The only change I made to the code you posted above was to close the quote
after "Your Third Bullet Pont" << & Char$(13)

Perfect!
 
D

David M. Marcovitz

Great. I'm glad it helped. That'll teach me to edit in the newsreader.
I'm glad you caught the missing close quote.
--David
 
J

Jeff H.

Adding the bullets is great, but the problem I am having is that I can't
indent the second bullet to be a sub bullet.

Thanks
Jeff
 
D

David M. Marcovitz

pptSlide.Shapes(2).TextFrame.TextRange.Paragraphs(2).IndentLevel = 2

How's that?

--David
--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
J

Jeff H.

It works great but everything after my first bullet is indented. I'll get my
logic straightened out and everything should be ok.

Thanks for the help.

Jeff
 
D

David M. Marcovitz

If you put that line AFTER the line that puts the third line of text in,
instead of right after the line that puts the second line of text in, it
should just indent the second line. That is, if there are already 3 lines,
and you indent line 2, just line 2 is indented. But if there are only 2
lines, and you indent line 2, then line 2 and any future lines will be
indented.
--David

David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
B

Brian Reilly, MVP

Echo,
"I don't know" is still in the batter's box. Not even on first.

All others, come here to the PPT Newsgroup and not only get on first,
second or third, but you can touch home plate and score.

Couldn't resist,

Brian Reilly, MVP
 

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