Here is a simple code to use the Find and Replace discussed in the last Post
The code should go in a code module in a WORD .docm File
Before rung the code, a text which includes BBCode Code Tags , should be selected in a Word document.
The Code makes a temporary File, "TempBBCodeCopy1.docx", holding the original selected text, then removes the BB Code Code Tags from the text and saves that as another temporary File, "TempNoBBCodeCopy2.docx"
Code:
Sub WegDaMitHansPaulAlan() ' http://www.eileenslounge.com/viewtopic.php?f=26&t=26030#p202223
Rem Code Part 1) make two temporary Word Files with and without BB Code
Rem 1) Copy selection to Clipboard
Selection.Copy
Rem 2) Make temporary WORD document
Documents.Add: ActiveDocument.Content.Paste
' 2b) Copy of Full Text with BB Code
Dim FullFilePathAndFullNameBBCode As String
ActiveDocument.SaveAs Filename:="TempBBCodeCopy1.docx", FileFormat:=wdFormatXMLDocument
Let FullFilePathAndFullNameBBCode = ActiveDocument.Path & "\" & ActiveDocument.Name
Rem 3) Replace Code tag pairs with what is in between
Selection.WholeStory
With Selection.Find
.ClearFormatting: .Replacement.ClearFormatting
.Wrap = wdFindStop
.MatchWildcards = True '
.Text = "[\[]([!=\]]@)(*\])(*)\[/(\1)\]" ' 8 sections, 4 identified with ( ) but I only need two ( )
.Replacement.Text = "\3" ' The third of the 4 sections identified with a ( )
.Execute Replace:=wdReplaceAll
End With
' 3b) Copy of Colored Text without BB Code Code tags
Dim FullFilePathAndFullNameNoBBCode As String
ActiveDocument.SaveAs Filename:="TempNoBBCodeCopy2.docx", FileFormat:=wdFormatXMLDocument
Let FullFilePathAndFullNameNoBBCode = ActiveDocument.Path & "\" & ActiveDocument.Name
Rem 4) "Reset the "Find Replace Text Dialogue" "Thing" "
ActiveDocument.Select
Selection.WholeStory
With Selection.Find
.ClearFormatting: .Replacement.ClearFormatting: .Text = "": .Replacement.Text = "": .Forward = True: .Wrap = wdFindAsk: .Format = False: .MatchCase = False: .MatchWholeWord = False: .MatchKashida = False: .MatchDiacritics = False: .MatchAlefHamza = False: .MatchControl = False: .MatchWildcards = False: .MatchSoundsLike = False: .MatchAllWordForms = False '
End With
Rem 5) Option to close / kill document
ActiveDocument.Close (wdDoNotSaveChanges)
'Kill FullFilePathAndFullNameBBCode
'Kill FullFilePathAndFullNameNoBBCode
End Sub ' End Code Part 1)
Bookmarks