none
Analyse FirstLine Indentations and View RRS feed

  • Question

  • Hi guys,

    I would like to know that there is any way or method related to VBA to check all first line indentations or any other paragraph property for that matter and view them with a message.

    For an example there is 10 paragraphs with firstline indentation of 0.5" and another 10 with firstline indentation of 0.25". My end goal is to view in a message box 0.5" and 0.25". Simply macro should go through the document and display how many firstline indentation indentations in the document.

    Problem is Duplicates should display as one. I really appreciate any input from the community. 

    Thanks in advance.

    Regards

    ______________________________

    Supun Samarakoon


    • Edited by Supunsam Wednesday, July 20, 2016 5:00 PM
    Wednesday, July 20, 2016 4:57 PM

Answers

  • Here is a macro. You can easily adapt it to gather different information, e.g. LeftIndent, LineSpacing etc.

    Indents are measured in points, so I used the PointsToInches function to convert the values to inches.

    Sub ListIndents()
        Dim par As Paragraph
        Dim col As New Collection
        Dim itm As Variant
        Dim strList As String
        On Error Resume Next
        For Each par In ActiveDocument.Paragraphs
            col.Add Item:=par.FirstLineIndent, Key:=CStr(par.FirstLineIndent)
        Next par
        On Error GoTo 0
        For Each itm In col
            strList = strList & vbCrLf & Application.PointsToInches(itm) & Chr(34)
        Next itm
        MsgBox "First line indents:" & strList, vbInformation
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Supunsam Thursday, July 21, 2016 7:37 PM
    Wednesday, July 20, 2016 5:16 PM

All replies

  • Here is a macro. You can easily adapt it to gather different information, e.g. LeftIndent, LineSpacing etc.

    Indents are measured in points, so I used the PointsToInches function to convert the values to inches.

    Sub ListIndents()
        Dim par As Paragraph
        Dim col As New Collection
        Dim itm As Variant
        Dim strList As String
        On Error Resume Next
        For Each par In ActiveDocument.Paragraphs
            col.Add Item:=par.FirstLineIndent, Key:=CStr(par.FirstLineIndent)
        Next par
        On Error GoTo 0
        For Each itm In col
            strList = strList & vbCrLf & Application.PointsToInches(itm) & Chr(34)
        Next itm
        MsgBox "First line indents:" & strList, vbInformation
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Supunsam Thursday, July 21, 2016 7:37 PM
    Wednesday, July 20, 2016 5:16 PM
  • Thank you very much Hans.. This is exactly what i was hoping for. If i could confirm just one thing. Can i get the count as well with this. If i can do that, what part should i modify in this??

    Regards,

    __________________________________

    Supun Samarakoon


    • Edited by Supunsam Thursday, July 21, 2016 7:42 PM
    Thursday, July 21, 2016 7:40 PM
  • If you want to count the number of unique indents: after the For Each par ... Next par loop, col.Count returns this number. For example:

        MsgBox "There are " & col.Count " different first line indents:" & strList, vbInformation



    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Thursday, July 21, 2016 9:18 PM
  • Wow. Thanks much Hans..

    Regards.

    _________________________

    Supun Samarakoon

    Friday, July 22, 2016 1:58 PM