确定子弹列表条目的级别

时间:2013-03-07 09:16:01

标签: vba powerpoint powerpoint-vba

我在Powerpoint中有一个包含如下分层列表的文本框:

* Level 1
  - Level 2
    . Level 3
    . Level 3 again
  - Level 2 again
* Level 1 again

格式化为子弹列表。

基于此文本(这是一个议程),我正在为每一行创建一个幻灯片,并以该行作为标题:

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

我的问题是:我如何弄清楚每个子弹的等级是多少?

我不是只把每一行写成标题,而是选择“等级1”和“等级”。 2级>等级3“作为标题,即某种面包屑。

1 个答案:

答案 0 :(得分:1)

好的,找到了解决方案 - 每个Line都有.ParagraphFormat.IndentLevel可以使用。这是将分层列表从选定文本框转换为带有面包屑作为标题的新幻灯片的最终代码:

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