Indentlevel property in PowerPoint

G

Guest

Hello,

I'm creating a PPT with info in an Excel worksheet. Everything works great
except when I add text to a textrange I can't get the indent level to work
correctly. It only applies my indent level to the last line in the
textrange. As a result, if I call my function once, the indent works fine.
If I call the function again, to add an additional line to my textrange, the
line which had a previous indentlevel = 2 reverts to an indentlevel = 1 and
the newly added line takes on the correct indentlevel = 2. If I explicitly
state which lines I want indented, everything works fine. (i.e
..TextFrame.textrange.Lines(2, 1).IndentLevel = 2
..TextFrame.textrange.Lines(3, 1).IndentLevel = 2
)
In my function I try to pass in the starting line number and if I do this,
it doesn't work. (i.e.
..Lines(currentlinenum, 1).IndentLevel = 2
)...where currentlinenum is the number of the last line in the textrange

Any ideas? I'm going out of my mind trying to figure this seeminly simple
thing out. Here's my function if it helps:

'where I'm calling my function:
Call addPhaseIInterfaceText(Worksheets("Setup").Range("A25"),
Worksheets("Setup").Range("B25"), _
Worksheets("Setup").Range("C25"),
Worksheets("Setup").Range("D25"))

Call addPhaseIInterfaceText(Worksheets("Setup").Range("A26"),
Worksheets("Setup").Range("B26"), _
Worksheets("Setup").Range("C26"),
Worksheets("Setup").Range("D26"))

the function:

Private Function addPhaseIInterfaceText(InterfaceType As String, PhaseI As
String, PhaseINew As String, _
PhaseII As String)

Dim currentlinenum As Integer
' made a public variable Dim additionalInterfaces As String

'additionalInterfaces = "Additional Recommended Interfaces"

objPPT.Presentations(1).Slides("CurrentInterfaces").Select
Set mydocument = objPPT.Presentations(1).Slides("PhaseIInterfaces")

If PhaseI = "YES" Then
If PhaseINew = "YES" Then
With mydocument.Shapes("PhaseIInterfacesText").TextFrame.textrange
'MsgBox .Text
.Text = .Text & Chr(13) & InterfaceType
'MsgBox .Text

currentlinenum =
mydocument.Shapes("PhaseIInterfacesText").TextFrame.textrange.Lines.Count
MsgBox "Line to be indented=" & str(currentlinenum)
.Lines(currentlinenum, 1).IndentLevel = 2
MsgBox "indented"
End With
Else
MsgBox "else"
additionalInterfaces = additionalInterfaces & Chr(13) &
InterfaceType
End If
Else
Exit Function
End If
End Function


Thanks in advance.
 
G

Guest

After further testing I've narrowed it down. When I run my function a second
time to add an additional line to my textrange with:

..Text = .Text & Chr(13) & InterfaceType

It removes my previous indent levels. Anyone know a way to get around this?

Thanks.
 
D

David M. Marcovitz

Here's what's happening (followed by the solution). When you do

..Text = .Text & SomeOtherStuff

You are not actually adding text to the text box, you are replacing all
the text in the text box with new text that happens to be the same as the
old text plus something. Unfortunately, by replacing all the text, the
formatting doesn't come along for the ride. Instead you want to use
InsertAfter to actually add some stuff to the end. Here is a simple
example:

Sub AddText()
newText = InputBox("What's the text?")
ActivePresentation.SlideShowWindow.View.Slide. _
Shapes(2).TextFrame.TextRange _
.InsertAfter (Chr$(13) + newText)
End Sub

This simply adds new text to the end of the current slide's second shape
and doesn't mess up the earlier formatting.

--David

--
David M. Marcovitz
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 

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