I have a textbox in Powerpoint that contains a hierarchical list like this:
* Level 1 - Level 2 . Level 3 . Level 3 again - Level 2 again * Level 1 again
This is formatted as a bullet list.
Based on this text (which is an agenda), I'm creating a slide for every line with the line as the title:
Set shpSource = ActiveWindow.Selection.ShapeRange
Set pre = ActivePresentation
Set sli = ActiveWindow.Selection.SlideRange(1)
For Each varStr In Split(shpSource.TextFrame2.TextRange, vbCr)
Set sli = pre.Slides.AddSlide(sli.SlideIndex + 1, sli.CustomLayout)
sli.Shapes(2).TextFrame.TextRange = varStr
Next
My question is: How can I figure out, which level each bullet is?
Instead of only writing each line as title, I'd rather have something like `Level 1 > Level 2 > Level 3" as title, ie. some kind of breadcrumbs.
Okay, found the solution - each Line
has .ParagraphFormat.IndentLevel
that can be used. Here's the final code to convert a hierarchical list from a selected text box to new slides with breadcrumbs as titles:
Sub ConvertAgenda()
Dim shpSource As ShapeRange
Dim pre As Presentation
Dim sli As Slide
Dim trng As TextRange2
Dim strL1 As String, strL2 As String, strFull As String, strCurrent As String
Set shpSource = ActiveWindow.Selection.ShapeRange
Set pre = ActivePresentation
Set sli = ActiveWindow.Selection.SlideRange(1)
For Each trng In shpSource.TextFrame2.TextRange.Lines
strCurrent = Left(trng, Len(trng) - 1)
Select Case trng.ParagraphFormat.IndentLevel
Case 1:
strL1 = strCurrent
strFull = strCurrent
Case 2:
strL2 = strCurrent
strFull = strL1 & " > " & strCurrent
Case 3:
strFull = strL1 & " > " & strL2 & " > " & strCurrent
End Select
Set sli = pre.Slides.AddSlide(sli.SlideIndex + 1, sli.CustomLayout)
sli.Shapes(2).TextFrame.TextRange = strFull
Next
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.