vb.net word find replace help

PunkStar

New member
Joined
Mar 7, 2007
Messages
2
Hi all,

Heres the deal. I have a word document that I want to replace some tags in. I have 2 types of tags. <%var%> <$par$>. The first (%) is used to insert variables. The second ($) is used in pairs to either include or omit sections of the document. The second Im coding into a function that takes a bool, if true the section should be kept but the tags should be removed. if false the section should be removed between the 2 pairs of tags, including the tags.

Ive managed to code the first, and the include piece of the second. I however am having an issue selecting the range from one <$tag$> to the next <$tag$>. Any help would be appreciated.

I should also note, all of the ($) pairs are unique pairs. so there is no worry about deleting too much. Anything between the two tags should be removed, with no exception.

Thanks for any help.
Zach
 
Wow, thanks for all the help guys. In case anyone out there hits this problem, heres the answer.

Code:
Public Sub Evaluate(ByVal Var As String, ByVal Keep As Boolean, ByVal doc As Word.Document)
    If Keep Then just remove this set of tags
        With doc.Content.Find
            .ClearFormatting()
            .Text = Var
            With .Replacement
                .ClearFormatting()
                .Text = ""
            End With
            .Execute(Replace:=Word.WdReplace.wdReplaceAll)
        End With

    Else remove this set of tags and everything between them
        With doc.Content.Find
            .ClearFormatting()
            .MatchWildcards = True
            .Text = "(" & Var & "*" & Var & ")"
            With .Replacement
                .ClearFormatting()
                .Text = ""
            End With
            .Execute(Replace:=Word.WdReplace.wdReplaceAll)
        End With
    End If
End Sub
 
Back
Top