1

我在 Powerpoint 中有一个文本框,其中包含这样的分层列表:

* 1级
  - 2级
    . 3级
    . 又是3级
  - 再次达到 2 级
* 再次达到 1 级

这被格式化为项目符号列表。

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

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

我的问题是:我怎样才能弄清楚每个子弹的级别?

我宁愿把每一行写成标题,我宁愿用“Level 1 > Level 2 > Level 3”作为标题,即某种面包屑。

4

1 回答 1

2

好的,找到了解决方案 - 每个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
于 2013-03-07T09:32:22.713 回答