none
Make an add-in that replaces certain text in a VSTO word file

    Question

  • I have a document with excessive white space. I would like to click a button and replace the white space.
    Friday, January 4, 2019 7:17 PM

All replies

  • The code in VBA would be

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    '
        Selection.Copy
        Selection.MoveUp Unit:=wdLine, Count:=1
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "                    "
            .Replacement.Text = "^t"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
        Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        Selection.Copy
        Selection.MoveUp Unit:=wdLine, Count:=1
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = vbTab & " "
            .Replacement.Text = "^t"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    

    I would like the VB.net or C# code

    Friday, January 11, 2019 8:32 PM