Indenting bullets via code

S

Scott

When adding text to a slide via the C# interop libraries in VS 2008 for a PPT
2007 file, how do I indent the bullets? I can add multiple lines of text and
each is a bullet point, as desired, but I can't get individual lines to be
sub-bullets.

For example, I want

- Bullet point 1
- Bullet point 1.1
- Bullet point 1.2
- Bullet point 2

I've tried setting the range's indent property but can't seem to make this
work. Any help would be greatly appreciated.
 
D

David M. Marcovitz

I don't know C#, but perhaps you can translate this VBA code:

ActivePresentation.Slides(1).Shapes(2).TextFrame _
.TextRange.Paragraphs(3).IndentLevel = 2

It takes the first slide, second shape, and indents the third paragraph
to be a sub-bullet.

--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/
 
S

Scott

I don't know C#, but perhaps you can translate this VBA code:
ActivePresentation.Slides(1).Shapes(2).TextFrame _
.TextRange.Paragraphs(3).IndentLevel = 2

If I put that VBA code into PPT 2007 it does exactly what I'm looking for.
From C# it doesn't seem to work though. I'm setting the bullets like this:

PowerPoint.Slide slide = presentation.Slides.Add(i++,
PowerPoint.PpSlideLayout.ppLayoutText);
PowerPoint.TextRange range =
slide.Shapes[2].TextFrame.TextRange;
range.ParagraphFormat.Bullet.UseTextFont =
Office.MsoTriState.msoTrue;

range.Text = <multi-line text here>;

The text is appearing, so I know I have the range variable set properly.
Then I try to set the indent, like this:

range.Paragraphs(3, 1).IndentLevel = 2;

The Paragraphs() function via the interop libraries wants a 'start' and
'length' parameter. I am guessing length means the number of paragraphs to
apply this to, but maybe not?

I get no exceptions from the code, it just doesn't do anything.
 
D

David M. Marcovitz

I'm not sure what to tell you. It looks like you are doing about the same
thing. I assume you tried fiddling with those numbers. For example, if
you only have 3 paragraphs, maybe using 2 (perhaps your numbering starts
at 0) or trying different things for the length parameter. Sorry. Maybe a
C# expert will pop in here and help.
--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/

I don't know C#, but perhaps you can translate this VBA code:

ActivePresentation.Slides(1).Shapes(2).TextFrame _
.TextRange.Paragraphs(3).IndentLevel = 2

If I put that VBA code into PPT 2007 it does exactly what I'm looking
for. From C# it doesn't seem to work though. I'm setting the bullets
like this:

PowerPoint.Slide slide = presentation.Slides.Add(i++,
PowerPoint.PpSlideLayout.ppLayoutText);
PowerPoint.TextRange range =
slide.Shapes[2].TextFrame.TextRange;
range.ParagraphFormat.Bullet.UseTextFont =
Office.MsoTriState.msoTrue;

range.Text = <multi-line text here>;

The text is appearing, so I know I have the range variable set
properly. Then I try to set the indent, like this:

range.Paragraphs(3, 1).IndentLevel = 2;

The Paragraphs() function via the interop libraries wants a 'start'
and 'length' parameter. I am guessing length means the number of
paragraphs to apply this to, but maybe not?

I get no exceptions from the code, it just doesn't do anything.
 
S

Scott

The trick is the newline character. If I replace the \n at the end of my
lines with a \r character, then the Paragraphs() method works properly, which
lets me set the IndentLevel.

Grumble grumble :)
 
S

Steve Rindsberg

The trick is the newline character. If I replace the \n at the end of my
lines with a \r character, then the Paragraphs() method works properly, which
lets me set the IndentLevel.

Grumble grumble :)

Ah, well that makes sense. Newline probably puts a linebreak rather than a
paragraph break in the text, so you only had one paragraph.

You could use the Lines collection to return the third line (but in this case it
wouldn't help because Lines don't have indents, just paragraphs).
 

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