Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...