Word VBA copy text formatted text in a certain font to a file and other formatting in other file

From a comparison docx file I need to extract into two word files the text formatted as strikethrough in one docx file and the text formatted as double underline in another docx file to be able to perform the wordcount of newly inserted and deleted text separately. To do this, I wrote this macro, that actually activates the correct files, but only copies and pastes the formatting resulting from the first search.

    Sub WSC_extraction_for_wordcount()
    'This macro extracts double underlined text to the file "target_ins"
    'This macro extracts strikethrough text to the file "target_del"

    Application.ScreenUpdating = False
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting

    'STRIKETHROUGH processing
    Do
    With Selection.Find.Font
    .StrikeThrough = True 'Then
    Selection.Find.Execute FindText:="", Forward:=True, Format:=True
    Selection.Cut
    Windows("target_del.docx").Activate
    Selection.PasteAndFormat (wdPasteDefault)
    Selection.TypeParagraph
    Windows("source.docx").Activate
    End With

    'DOUBLE UNDERLINE processing
    With Selection.Find.Font
    .Underline = wdUnderlineDouble = True 'Then
    Selection.Find.Execute FindText:="", Forward:=True, Wrap:=wdFindContinue, Format:=True
    Selection.Cut
    Windows("target_ins.docx").Activate
    Selection.PasteAndFormat (wdPasteDefault)
    Selection.TypeParagraph
    Windows("source.docx").Activate
    End With
    Loop
    End Sub

I would be grateful if someone could help me in transforming the options into something like: if the next sentence you encounter is formatted as strikethrough, copy it to file target_del, if the next sentence you encounter is formatted as double underlined, copy it to the file target_ins.

Thank you in advance!



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations