0

I'm trying to write two routines, one that picks up a paragraphs bullet settings including (especially indenting) but am getting nowhere picking up the settings. I tried these two variations but I don't get the indent positions, just a value of -2.14784E+09...

    MsgBox shp.TextFrame2.textRange.ParagraphFormat.FirstLineIndent
    MsgBox shp.TextFrame2.textRange.ParagraphFormat.leftIndent

    MsgBox shp.textFrame.Ruler.Levels(1).FirstMargin
    MsgBox shp.textFrame.Ruler.Levels(1).LeftMargin

Attached is the code I'm using to view the properties before implementing the pick-up and apply routines.

Thanks in advance for your help.

Sub ShowCurrentParagraphInfo()
    Dim sel As Selection
    Set sel = ActiveWindow.Selection

    If sel.Type <> ppSelectionText Then
        MsgBox "Please place the cursor inside a text box.", vbExclamation
        Exit Sub
    End If

    Dim tr As textRange
    Set tr = sel.textRange

    Dim shp As shape
    Set shp = sel.shapeRange(1)

    Dim fullText As textRange
    Set fullText = shp.textFrame.textRange


    Dim paraIndex As Long
    paraIndex = GetParagraphIndexFromTextRange(tr, fullText)

    If paraIndex > 0 Then
        Dim para As textRange
        Set para = fullText.Paragraphs(paraIndex)

        MsgBox shp.TextFrame2.textRange.ParagraphFormat.FirstLineIndent
        MsgBox shp.TextFrame2.textRange.ParagraphFormat.leftIndent

        MsgBox shp.textFrame.Ruler.Levels(1).FirstMargin
        MsgBox shp.textFrame.Ruler.Levels(1).LeftMargin
        
        Dim indentLevel As Long
        Dim bulletChar As String
        Dim bulletSize As Variant
        Dim bulletFont As String
        Dim bulletColorRGB As String
        Dim leftIndent As Single

        With para.ParagraphFormat
            indentLevel = para.indentLevel
            bulletChar = .Bullet.Character
            bulletSize = .Bullet.RelativeSize * 100
            bulletFont = .Bullet.Font.Name
            If .Bullet.Type <> ppBulletNone Then
                On Error Resume Next
                bulletColorRGB = .Bullet.Font.Color.RGB
                On Error GoTo 0
            Else
                bulletColorRGB = "N/A"
            End If
        End With

        MsgBox "You are in paragraph number: " & paraIndex & vbCrLf & _
               "Indent level: " & indentLevel & vbCrLf & _
               "Bullet character: " & bulletChar & vbCrLf & _
               "Bullet relative size: " & bulletSize & "%" & vbCrLf & _
               "Bullet font: " & bulletFont & vbCrLf & _
               "Bullet color (RGB): " & bulletColorRGB & vbCrLf & _
               "Left indent: " & leftIndent & vbCrLf & _
               "Text: " & para.Text, vbInformation
    Else
        MsgBox "Couldn't detect the paragraph number.", vbExclamation
    End If
End Sub

Function GetParagraphIndexFromTextRange(tr As textRange, fullText As textRange) As Long
    Dim i As Long
    For i = 1 To fullText.Paragraphs.count
        Dim para As textRange
        Set para = fullText.Paragraphs(i)

        If tr.Start >= para.Start And tr.Start < para.Start + para.length Then
            GetParagraphIndexFromTextRange = i
            Exit Function
        End If
    Next i
    GetParagraphIndexFromTextRange = -1
End Function
1
  • 1
    What is your use case for this? Your code would produce a presentation that would be entirely locally formatted, a nightmare scenario. PowerPoint works by inheritance. The Slide Master inherits fonts and colors from the Theme. The Slide Layouts inherit text levels, title and footers from the Slide Master. The Slides inherit placeholder layout and altered text levels from the Slide Layouts. Instead, you should be creating a slide master and/or layouts that have the preferred formatting for the text levels, then applying those layouts to the slides. Commented Jul 8 at 21:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.