none
Parsing a docx File for Italic Highlighting and Footnotes RRS feed

  • Question

  • Hello Everyone,

    I have a very large wordfile. I would like to parse and get Locations of for example Italic Highlighting and Footnotes. Does anybody have a good example how to get started on this?

    I would appreciate any help greatly, kind blessings


    Andreas Bolliger

    Monday, May 12, 2014 9:36 PM

Answers

  • Hi Bolliger,

    Based on the description, you want to find the specific object in Word document. An easy way is recording a macro. Though the code is not perfect but it gives us a good start. Here are some code by recording macros and I make little changes:

    Sub FindItalic()
    
        Selection.Find.ClearFormatting
    
        Selection.Find.Font.Italic = True
    
        With Selection.Find
    
            .Text = ""
    
            .Replacement.Text = ""
    
            .Forward = True
    
            .Wrap = wdFindContinue
    
            .Format = True
    
            .MatchCase = False
    
            .MatchWholeWord = False
    
            .MatchByte = False
    
            .MatchWildcards = False
    
            .MatchSoundsLike = False
    
            .MatchAllWordForms = False
    
        End With
    
        Selection.Find.Execute
    
        
    
        If Selection.Find.Found Then
    
            MsgBox "Italic Start:" & Selection.Start & " Italic end:" & Selection.End
    
        End If
    
    End Sub
    
    Sub FindHight()
    
        Selection.Find.ClearFormatting
    
        Selection.Find.Highlight = True
    
        With Selection.Find
    
            .Text = ""
    
            .Replacement.Text = ""
    
            .Forward = True
    
            .Wrap = wdFindContinue
    
            .Format = True
    
            .MatchCase = False
    
            .MatchWholeWord = False
    
            .MatchByte = False
    
            .MatchWildcards = False
    
            .MatchSoundsLike = False
    
            .MatchAllWordForms = False
    
        End With
    
        Selection.Find.Execute
    
        
    
         If Selection.Find.Found Then
    
            MsgBox "Highlight Start:" & Selection.Start & " Highlight end:" & Selection.End
    
        End If
    
    End Sub
    
    Sub FindFootNote()
    
        Selection.Find.ClearFormatting
    
        With Selection.Find
    
            .Text = "^f"
    
            .Replacement.Text = ""
    
            .Forward = True
    
            .Wrap = wdFindAsk
    
            .Format = False
    
            .MatchCase = False
    
            .MatchWholeWord = False
    
            .MatchByte = False
    
            .MatchWildcards = False
    
            .MatchSoundsLike = False
    
            .MatchAllWordForms = False
    
        End With
    
        Selection.Find.Execute
    
        
    
         If Selection.Find.Found Then
    
            MsgBox "FootNote Start:" & Selection.Start & " FootNote end:" & Selection.End
    
        End If
    
    End Sub
    

    You can get more detail about Find object from link below:
    How to: Programmatically Search for and Replace Text in Documents

    Find Object (Word)

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 13, 2014 9:04 AM
    Moderator
  • Hi Andreas

    Start by recording a macro using Find/Replace in the UI. Find/Replace can find formatting and replace that formatting with other formatting.

    So, in the UI, click in the "find" box, go to the Formatting button, choose Font and italic.

    Then click in the Replace box and repeat the steps, choosing Bold.

    Click Replace All.

    The macro recorder should pick up all the steps...


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by BolligeA Tuesday, May 13, 2014 3:00 PM
    Tuesday, May 13, 2014 2:57 PM
    Moderator

All replies

  • Hi Bolliger,

    Based on the description, you want to find the specific object in Word document. An easy way is recording a macro. Though the code is not perfect but it gives us a good start. Here are some code by recording macros and I make little changes:

    Sub FindItalic()
    
        Selection.Find.ClearFormatting
    
        Selection.Find.Font.Italic = True
    
        With Selection.Find
    
            .Text = ""
    
            .Replacement.Text = ""
    
            .Forward = True
    
            .Wrap = wdFindContinue
    
            .Format = True
    
            .MatchCase = False
    
            .MatchWholeWord = False
    
            .MatchByte = False
    
            .MatchWildcards = False
    
            .MatchSoundsLike = False
    
            .MatchAllWordForms = False
    
        End With
    
        Selection.Find.Execute
    
        
    
        If Selection.Find.Found Then
    
            MsgBox "Italic Start:" & Selection.Start & " Italic end:" & Selection.End
    
        End If
    
    End Sub
    
    Sub FindHight()
    
        Selection.Find.ClearFormatting
    
        Selection.Find.Highlight = True
    
        With Selection.Find
    
            .Text = ""
    
            .Replacement.Text = ""
    
            .Forward = True
    
            .Wrap = wdFindContinue
    
            .Format = True
    
            .MatchCase = False
    
            .MatchWholeWord = False
    
            .MatchByte = False
    
            .MatchWildcards = False
    
            .MatchSoundsLike = False
    
            .MatchAllWordForms = False
    
        End With
    
        Selection.Find.Execute
    
        
    
         If Selection.Find.Found Then
    
            MsgBox "Highlight Start:" & Selection.Start & " Highlight end:" & Selection.End
    
        End If
    
    End Sub
    
    Sub FindFootNote()
    
        Selection.Find.ClearFormatting
    
        With Selection.Find
    
            .Text = "^f"
    
            .Replacement.Text = ""
    
            .Forward = True
    
            .Wrap = wdFindAsk
    
            .Format = False
    
            .MatchCase = False
    
            .MatchWholeWord = False
    
            .MatchByte = False
    
            .MatchWildcards = False
    
            .MatchSoundsLike = False
    
            .MatchAllWordForms = False
    
        End With
    
        Selection.Find.Execute
    
        
    
         If Selection.Find.Found Then
    
            MsgBox "FootNote Start:" & Selection.Start & " FootNote end:" & Selection.End
    
        End If
    
    End Sub
    

    You can get more detail about Find object from link below:
    How to: Programmatically Search for and Replace Text in Documents

    Find Object (Word)

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 13, 2014 9:04 AM
    Moderator
  • Hi Andreas

    You need to define more exactly what you mean by "parsing" the file and getting locations.

    In addition, which version of Word are we dealing with?


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, May 13, 2014 10:06 AM
    Moderator
  • Thank you so very much for the Macro tip! Will certainly try that out!

    I have word 2013 and would like to get for example all Italic Texts in the current word Document and then change them to bold. All the Italic Texts would be replaced with Bold texts in the whole Document and override it.

    I would appreciate further help and ideas greatly, kind blessings


    Andreas Bolliger

    Tuesday, May 13, 2014 12:49 PM
  • Hi Andreas

    Start by recording a macro using Find/Replace in the UI. Find/Replace can find formatting and replace that formatting with other formatting.

    So, in the UI, click in the "find" box, go to the Formatting button, choose Font and italic.

    Then click in the Replace box and repeat the steps, choosing Bold.

    Click Replace All.

    The macro recorder should pick up all the steps...


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by BolligeA Tuesday, May 13, 2014 3:00 PM
    Tuesday, May 13, 2014 2:57 PM
    Moderator