PunkStar Posted March 7, 2007 Posted March 7, 2007 Hi all, Here's 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 I'm 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. I've 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 Quote
PunkStar Posted March 8, 2007 Author Posted March 8, 2007 Wow, thanks for all the help guys. In case anyone out there hits this problem, here's the answer. 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 Quote
Recommended Posts